diff --git a/Sources/ConsoleKit/Activity/ActivityBar.swift b/Sources/ConsoleKit/Activity/ActivityBar.swift index 0c8cae5..be992a1 100644 --- a/Sources/ConsoleKit/Activity/ActivityBar.swift +++ b/Sources/ConsoleKit/Activity/ActivityBar.swift @@ -52,11 +52,11 @@ struct ActivityBarWidthKey: Hashable, Equatable { extension Console { public var activityBarWidth: Int { get { - self.userInfo[AnySendableHashable(ActivityBarWidthKey())] as? Int ?? 25 + self.userInfo[ActivityBarWidthKey()] as? Int ?? 25 } set { - self.userInfo[AnySendableHashable(ActivityBarWidthKey())] = newValue + self.userInfo[ActivityBarWidthKey()] = newValue } } } diff --git a/Sources/ConsoleKit/Utilities/AnySendableHashable.swift b/Sources/ConsoleKit/Utilities/AnySendableHashable.swift index dddf26b..79dc47d 100644 --- a/Sources/ConsoleKit/Utilities/AnySendableHashable.swift +++ b/Sources/ConsoleKit/Utilities/AnySendableHashable.swift @@ -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 } + } }