A compile-time dependency injection pattern for Rust with zero runtime cost.
Services need other services:
impl OrderService {| import Foundation | |
| /// Represents a specific day in the Gregorian calendar as an integer offset. | |
| /// | |
| /// `CalendarDay` provides a timezone-stable way to identify calendar days. | |
| /// When created, it captures which Gregorian calendar day a date falls on | |
| /// according to the specified timezone, then stores this as an integer offset | |
| /// from Apple's reference date (January 1, 2001). | |
| /// | |
| /// This type is useful when you need to: |
| import SwiftUI | |
| struct DateComponentsTimelineSchedule: TimelineSchedule { | |
| let components: DateComponents | |
| let calendar: Calendar | |
| let matchingPolicy: Calendar.MatchingPolicy | |
| init( | |
| components: DateComponents, | |
| calendar: Calendar = .current, |
| struct OnChangeTask<T: Equatable>: ViewModifier { | |
| let value: T | |
| let action: () async -> Void | |
| @State private var updateCount = 0 | |
| func body(content: Content) -> some View { | |
| content | |
| .onChange(of: value) { | |
| updateCount += 1 | |
| } |
| import SwiftUI | |
| struct AttributedStringBuilder { | |
| @Stack var attributes: RichTextAttributes = .init() | |
| var string: AttributedString = "" | |
| mutating func text(_ span: String) { | |
| string += AttributedString(span, attributes: .init(attributes)) | |
| } | |
| @propertyWrapper | |
| struct Stack<Value> { | |
| private var history: [Value] | |
| init(wrappedValue initialValue: Value) { | |
| self.history = [initialValue] | |
| } | |
| var wrappedValue: Value { | |
| get { history[history.endIndex - 1] } |
$COMPONENT-NAME, which is @ followed by an $IDENTIFIER (e.g., @component-name).--- delimiters, specifies component attributes.| from itertools import zip_longest, chain | |
| from dataclasses import dataclass, field | |
| @dataclass | |
| class Tree: | |
| value: any | |
| children: list = field(default_factory=list) | |
| def levels(self): | |
| yield [self] |