-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve AnySendableHashable to match Hashable (#191)
- Loading branch information
Showing
2 changed files
with
19 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/// A `Sendable` version of the standard library's `AnyHashable` type. | ||
public struct AnySendableHashable: @unchecked Sendable, Hashable, ExpressibleByStringLiteral { | ||
// Note: @unchecked Sendable since there's no way to express that `wrappedValue` is Sendable, even though we ensure that it is in the init. | ||
let wrappedValue: AnyHashable | ||
|
||
public init(_ wrappedValue: some Hashable & Sendable) { | ||
self.wrappedValue = AnyHashable(wrappedValue) | ||
} | ||
|
||
public init(stringLiteral value: String) { | ||
self.init(value) | ||
} | ||
} | ||
|
||
extension AnySendableHashable: CustomStringConvertible, CustomDebugStringConvertible, CustomReflectable { | ||
public var description: String { self.wrappedValue.description } | ||
public var debugDescription: String { self.wrappedValue.debugDescription } | ||
public var customMirror: Mirror { self.wrappedValue.customMirror } | ||
} |