Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ for target in package.targets {
// https://docs.swift.org/compiler/documentation/diagnostics/nonisolated-nonsending-by-default/
settings.append(.enableUpcomingFeature("NonisolatedNonsendingByDefault"))

settings.append(.enableExperimentalFeature("AvailabilityMacro=Configuration 1.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0"))
settings.append(
.enableExperimentalFeature(
"AvailabilityMacro=Configuration 1.0:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0"
)
)

if enableAllCIFlags {
// Ensure all public types are explicitly annotated as Sendable or not Sendable.
Expand Down
43 changes: 43 additions & 0 deletions Sources/Configuration/ConfigKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
///
/// Keys can include additional context information that some providers use to
/// refine value lookups or provide more specific results.
@available(Configuration 1.0, *)
public struct ConfigKey: Sendable {

/// The hierarchical components that make up this configuration key.
Expand All @@ -42,10 +43,23 @@ public struct ConfigKey: Sendable {
self.components = components
self.context = context
}

/// Creates a new configuration key.
/// - Parameters:
/// - string: The string represenation of the key path, for example `"http.timeout"`.
/// - context: Additional context information for the key.
public init(_ string: String, context: [String: ConfigContextValue] = [:]) {
self = DotSeparatorKeyDecoder.decode(string, context: context)
}
}

@available(Configuration 1.0, *)
extension ConfigKey: Equatable {}

@available(Configuration 1.0, *)
extension ConfigKey: Hashable {}

@available(Configuration 1.0, *)
extension ConfigKey: Comparable {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public static func < (lhs: ConfigKey, rhs: ConfigKey) -> Bool {
Expand All @@ -67,6 +81,7 @@ extension ConfigKey: Comparable {
}
}

@available(Configuration 1.0, *)
extension ConfigKey: CustomStringConvertible {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public var description: String {
Expand All @@ -79,6 +94,15 @@ extension ConfigKey: CustomStringConvertible {
}
}

@available(Configuration 1.0, *)
extension ConfigKey: ExpressibleByStringLiteral {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public init(stringLiteral value: String) {
self = DotSeparatorKeyDecoder.decode(value, context: [:])
}
}

@available(Configuration 1.0, *)
extension ConfigKey: ExpressibleByArrayLiteral {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public init(arrayLiteral elements: String...) {
Expand All @@ -94,6 +118,7 @@ extension ConfigKey: ExpressibleByArrayLiteral {
///
/// Like relative keys, absolute keys consist of hierarchical components and
/// optional context information.
@available(Configuration 1.0, *)
public struct AbsoluteConfigKey: Sendable {

/// The hierarchical components that make up this absolute configuration key.
Expand All @@ -118,8 +143,13 @@ public struct AbsoluteConfigKey: Sendable {
}
}

@available(Configuration 1.0, *)
extension AbsoluteConfigKey: Equatable {}

@available(Configuration 1.0, *)
extension AbsoluteConfigKey: Hashable {}

@available(Configuration 1.0, *)
extension AbsoluteConfigKey: Comparable {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public static func < (lhs: AbsoluteConfigKey, rhs: AbsoluteConfigKey) -> Bool {
Expand All @@ -141,6 +171,7 @@ extension AbsoluteConfigKey: Comparable {
}
}

@available(Configuration 1.0, *)
extension AbsoluteConfigKey: CustomStringConvertible {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public var description: String {
Expand All @@ -153,6 +184,7 @@ extension AbsoluteConfigKey: CustomStringConvertible {
}
}

@available(Configuration 1.0, *)
extension AbsoluteConfigKey {

/// Creates a new absolute configuration key from a relative key.
Expand All @@ -162,6 +194,7 @@ extension AbsoluteConfigKey {
}
}

@available(Configuration 1.0, *)
extension AbsoluteConfigKey? {
/// Returns a new absolute configuration key by appending the given relative key.
/// - Parameter relative: The relative configuration key to append to this key.
Expand All @@ -178,6 +211,7 @@ extension AbsoluteConfigKey? {
}
}

@available(Configuration 1.0, *)
extension AbsoluteConfigKey {
/// Returns a new absolute configuration key by prepending the given relative key.
/// - Parameter prefix: The relative configuration key to prepend to this key.
Expand All @@ -201,6 +235,15 @@ extension AbsoluteConfigKey {
}
}

@available(Configuration 1.0, *)
extension AbsoluteConfigKey: ExpressibleByStringLiteral {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public init(stringLiteral value: String) {
self = .init(DotSeparatorKeyDecoder.decode(value, context: [:]))
}
}

@available(Configuration 1.0, *)
extension AbsoluteConfigKey: ExpressibleByArrayLiteral {
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
public init(arrayLiteral elements: String...) {
Expand Down
Loading
Loading