-
-
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.
Fix
AnySendableHashable
regression (#193)
* Unbreak the API * Make it all inlineable
- Loading branch information
Showing
2 changed files
with
15 additions
and
5 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 |
---|---|---|
@@ -1,19 +1,29 @@ | ||
/// 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. | ||
@usableFromInline | ||
let wrappedValue: AnyHashable | ||
|
||
@inlinable | ||
public init(_ wrappedValue: some Hashable & Sendable) { | ||
self.wrappedValue = AnyHashable(wrappedValue) | ||
} | ||
|
||
@inlinable | ||
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 } | ||
@inlinable public var description: String { self.wrappedValue.description } | ||
@inlinable public var debugDescription: String { self.wrappedValue.debugDescription } | ||
@inlinable public var customMirror: Mirror { self.wrappedValue.customMirror } | ||
} | ||
|
||
extension Dictionary where Key == AnySendableHashable { | ||
public subscript(key: some Hashable & Sendable) -> Value? { | ||
@inlinable get { self[AnySendableHashable(key)] } | ||
@inlinable set { self[AnySendableHashable(key)] = newValue } | ||
} | ||
} |