Files
swift-composable-architectu…/Sources/ComposableArchitecture/Internal/KeyPath+Sendable.swift
Stephen Celis d468b45abb wip
2024-10-17 14:17:30 -07:00

57 lines
1.9 KiB
Swift

#if compiler(>=6)
public typealias _SendableAnyKeyPath = any AnyKeyPath & Sendable
public typealias _SendablePartialKeyPath<Root> = any PartialKeyPath<Root> & Sendable
public typealias _SendableKeyPath<Root, Value> = any KeyPath<Root, Value> & Sendable
public typealias _SendableWritableKeyPath<Root, Value> = any WritableKeyPath<Root, Value>
& Sendable
public typealias _SendableReferenceWritableKeyPath<Root, Value> = any ReferenceWritableKeyPath<
Root, Value
>
& Sendable
public typealias _SendablePartialCaseKeyPath<Root> = any PartialCaseKeyPath<Root> & Sendable
public typealias _SendableCaseKeyPath<Root, Value> = any CaseKeyPath<Root, Value> & Sendable
#else
public typealias _SendableAnyKeyPath = AnyKeyPath
public typealias _SendablePartialKeyPath<Root> = PartialKeyPath<Root>
public typealias _SendableKeyPath<Root, Value> = KeyPath<Root, Value>
public typealias _SendableWritableKeyPath<Root, Value> = WritableKeyPath<Root, Value>
public typealias _SendableReferenceWritableKeyPath<Root, Value> = ReferenceWritableKeyPath<
Root, Value
>
public typealias _SendablePartialCaseKeyPath<Root> = PartialCaseKeyPath<Root>
public typealias _SendableCaseKeyPath<Root, Value> = CaseKeyPath<Root, Value>
#endif
@_transparent
func sendableKeyPath(
_ keyPath: AnyKeyPath
) -> _SendableAnyKeyPath {
#if compiler(>=6)
unsafeBitCast(keyPath, to: _SendableAnyKeyPath.self)
#else
keyPath
#endif
}
@_transparent
func sendableKeyPath<Root, Value>(
_ keyPath: KeyPath<Root, Value>
) -> _SendableKeyPath<Root, Value> {
#if compiler(>=6)
unsafeBitCast(keyPath, to: _SendableKeyPath<Root, Value>.self)
#else
keyPath
#endif
}
@_transparent
func sendableKeyPath<Root, Value>(
_ keyPath: WritableKeyPath<Root, Value>
) -> _SendableWritableKeyPath<Root, Value> {
#if compiler(>=6)
unsafeBitCast(keyPath, to: _SendableWritableKeyPath<Root, Value>.self)
#else
keyPath
#endif
}