Skip to content

Commit a11a984

Browse files
stephencelisp4checo
authored andcommitted
Conditionally conform UncheckedSendable to Hashable, Codable (#1575)
(cherry picked from commit 53ddc5904c065190d05c035ca0e4589cb6d45d61)
1 parent 4baef05 commit a11a984

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Sources/ComposableArchitecture/Effects/ConcurrencySupport.swift

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,28 @@ public struct UncheckedSendable<Value>: @unchecked Sendable {
397397
}
398398
}
399399

400-
extension UncheckedSendable: Equatable where Value: Equatable {
401-
public static func == (lhs: UncheckedSendable, rhs: UncheckedSendable) -> Bool {
402-
lhs.value == rhs.value
400+
extension UncheckedSendable: Equatable where Value: Equatable {}
401+
extension UncheckedSendable: Hashable where Value: Hashable {}
402+
403+
extension UncheckedSendable: Decodable where Value: Decodable {
404+
public init(from decoder: Decoder) throws {
405+
do {
406+
let container = try decoder.singleValueContainer()
407+
self.init(wrappedValue: try container.decode(Value.self))
408+
} catch {
409+
self.init(wrappedValue: try Value(from: decoder))
410+
}
411+
}
412+
}
413+
414+
extension UncheckedSendable: Encodable where Value: Encodable {
415+
public func encode(to encoder: Encoder) throws {
416+
do {
417+
var container = encoder.singleValueContainer()
418+
try container.encode(self.wrappedValue)
419+
} catch {
420+
try self.wrappedValue.encode(to: encoder)
421+
}
403422
}
404423
}
405424
#endif

0 commit comments

Comments
 (0)