Skip to content

Commit 5b1dfaf

Browse files
committed
Allow non-copyable Return types in with-style methods
1 parent 23c6b9b commit 5b1dfaf

19 files changed

+89
-89
lines changed

Sources/Configuration/ConfigProvider.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public protocol ConfigProvider: Sendable {
9797
/// - updatesHandler: The closure that processes the async sequence of value updates.
9898
/// - Throws: Provider-specific errors or errors thrown by the handler closure.
9999
/// - Returns: The value returned by the closure.
100-
func watchValue<Return>(
100+
func watchValue<Return: ~Copyable>(
101101
forKey key: AbsoluteConfigKey,
102102
type: ConfigType,
103103
updatesHandler: (
@@ -128,7 +128,7 @@ public protocol ConfigProvider: Sendable {
128128
/// - Parameter updatesHandler: The closure that processes the asynchronous sequence of snapshot updates.
129129
/// - Throws: Provider-specific errors or errors thrown by the handler closure.
130130
/// - Returns: The value returned by the closure.
131-
func watchSnapshot<Return>(
131+
func watchSnapshot<Return: ~Copyable>(
132132
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
133133
) async throws -> Return
134134
}

Sources/Configuration/ConfigProviderHelpers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension ConfigProvider {
4343
/// - Returns: The value returned by the handler closure.
4444
/// - Throws: Provider-specific errors or errors thrown by the handler.
4545
nonisolated(nonsending)
46-
public func watchValueFromValue<Return>(
46+
public func watchValueFromValue<Return: ~Copyable>(
4747
forKey key: AbsoluteConfigKey,
4848
type: ConfigType,
4949
updatesHandler: (
@@ -85,7 +85,7 @@ extension ConfigProvider {
8585
/// - Parameter updatesHandler: The closure that processes the async sequence of snapshot updates.
8686
/// - Returns: The value returned by the handler closure.
8787
/// - Throws: Provider-specific errors or errors thrown by the handler.
88-
nonisolated(nonsending) public func watchSnapshotFromSnapshot<Return>(
88+
nonisolated(nonsending) public func watchSnapshotFromSnapshot<Return: ~Copyable>(
8989
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
9090
) async throws -> Return {
9191
let (stream, continuation) = AsyncStream<any ConfigSnapshot>

Sources/Configuration/ConfigReader+internalHelpers.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ extension ConfigReader {
637637
/// - updatesHandler: A closure that handles the stream of updates, emits `nil` when no value is found.
638638
/// - Throws: An error if the watch operation fails.
639639
/// - Returns: The value returned by the updates handler.
640-
internal func watchValue<Value: Sendable, Return>(
640+
internal func watchValue<Value: Sendable, Return: ~Copyable>(
641641
forKey key: ConfigKey,
642642
type: ConfigType,
643643
isSecret: Bool,
@@ -713,7 +713,7 @@ extension ConfigReader {
713713
/// - updatesHandler: A closure that handles the stream of updates, emits the default when no value is found.
714714
/// - Throws: An error if the watch operation fails.
715715
/// - Returns: The value returned by the updates handler.
716-
internal func watchValue<Value: Sendable, Return>(
716+
internal func watchValue<Value: Sendable, Return: ~Copyable>(
717717
forKey key: ConfigKey,
718718
type: ConfigType,
719719
isSecret: Bool,
@@ -790,7 +790,7 @@ extension ConfigReader {
790790
/// or the value cannot be unwrapped.
791791
/// - Throws: An error if the watch operation fails.
792792
/// - Returns: The value returned by the updates handler.
793-
internal func watchRequiredValue<Value: Sendable, Return>(
793+
internal func watchRequiredValue<Value: Sendable, Return: ~Copyable>(
794794
forKey key: ConfigKey,
795795
type: ConfigType,
796796
isSecret: Bool,

Sources/Configuration/ConfigReader+methods.swift

Lines changed: 42 additions & 42 deletions
Large diffs are not rendered by default.

Sources/Configuration/ConfigReader+methods.swift.gyb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ extension ConfigReader {
698698
/// produces `nil` if the value is missing or can't be converted.
699699
/// - Returns: The result produced by the handler.
700700
/// - Throws: Rethrows any error thrown by the handler or the underlying watch operation.
701-
public func watch${primitive_type["name"]}<Return>(
701+
public func watch${primitive_type["name"]}<Return: ~Copyable>(
702702
forKey key: ConfigKey,
703703
isSecret: Bool = false,
704704
fileID: String = #fileID,
@@ -741,7 +741,7 @@ extension ConfigReader {
741741
/// produces the default value if the provider returned a `nil` value or conversion failed.
742742
/// - Returns: The result produced by the handler.
743743
/// - Throws: Rethrows any error thrown by the handler or the underlying watch operation.
744-
public func watch${primitive_type["name"]}<Return>(
744+
public func watch${primitive_type["name"]}<Return: ~Copyable>(
745745
forKey key: ConfigKey,
746746
isSecret: Bool = false,
747747
default defaultValue: ${primitive_type["type"]},
@@ -785,7 +785,7 @@ extension ConfigReader {
785785
/// produces an error if the provider returned a `nil` value or if the value was of an incorrect type.
786786
/// - Returns: The result produced by the handler.
787787
/// - Throws: Rethrows any error thrown by the handler or the underlying watch operation.
788-
public func watchRequired${primitive_type["name"]}<Return>(
788+
public func watchRequired${primitive_type["name"]}<Return: ~Copyable>(
789789
forKey key: ConfigKey,
790790
isSecret: Bool = false,
791791
fileID: String = #fileID,
@@ -834,7 +834,7 @@ extension ConfigReader {
834834
/// produces `nil` if the value is missing or can't be converted.
835835
/// - Returns: The result produced by the handler.
836836
/// - Throws: Rethrows any error thrown by the handler or the underlying watch operation.
837-
public func watchString<Value: ${string_convertible_type["protocol"]} & Sendable, Return>(
837+
public func watchString<Value: ${string_convertible_type["protocol"]} & Sendable, Return: ~Copyable>(
838838
forKey key: ConfigKey,
839839
as type: Value.Type = Value.self,
840840
isSecret: Bool = false,
@@ -879,7 +879,7 @@ extension ConfigReader {
879879
/// produces the default value if the provider returned a `nil` value or conversion failed.
880880
/// - Returns: The result produced by the handler.
881881
/// - Throws: Rethrows any error thrown by the handler or the underlying watch operation.
882-
public func watchString<Value: ${string_convertible_type["protocol"]} & Sendable, Return>(
882+
public func watchString<Value: ${string_convertible_type["protocol"]} & Sendable, Return: ~Copyable>(
883883
forKey key: ConfigKey,
884884
as type: Value.Type = Value.self,
885885
isSecret: Bool = false,
@@ -925,7 +925,7 @@ extension ConfigReader {
925925
/// produces an error if the provider returned a `nil` value or if the value was of an incorrect type.
926926
/// - Returns: The result produced by the handler.
927927
/// - Throws: Rethrows any error thrown by the handler or the underlying watch operation.
928-
public func watchRequiredString<Value: ${string_convertible_type["protocol"]} & Sendable, Return>(
928+
public func watchRequiredString<Value: ${string_convertible_type["protocol"]} & Sendable, Return: ~Copyable>(
929929
forKey key: ConfigKey,
930930
as type: Value.Type = Value.self,
931931
isSecret: Bool = false,
@@ -973,7 +973,7 @@ extension ConfigReader {
973973
/// produces `nil` if the value is missing or can't be converted.
974974
/// - Returns: The result produced by the handler.
975975
/// - Throws: Rethrows any error thrown by the handler or the underlying watch operation.
976-
public func watchStringArray<Value: ${string_convertible_type["protocol"]} & Sendable, Return>(
976+
public func watchStringArray<Value: ${string_convertible_type["protocol"]} & Sendable, Return: ~Copyable>(
977977
forKey key: ConfigKey,
978978
as type: Value.Type = Value.self,
979979
isSecret: Bool = false,
@@ -1018,7 +1018,7 @@ extension ConfigReader {
10181018
/// produces the default value if the provider returned a `nil` value or conversion failed.
10191019
/// - Returns: The result produced by the handler.
10201020
/// - Throws: Rethrows any error thrown by the handler or the underlying watch operation.
1021-
public func watchStringArray<Value: ${string_convertible_type["protocol"]} & Sendable, Return>(
1021+
public func watchStringArray<Value: ${string_convertible_type["protocol"]} & Sendable, Return: ~Copyable>(
10221022
forKey key: ConfigKey,
10231023
as type: Value.Type = Value.self,
10241024
isSecret: Bool = false,
@@ -1064,7 +1064,7 @@ extension ConfigReader {
10641064
/// produces an error if the provider returned a `nil` value or if the value was of an incorrect type.
10651065
/// - Returns: The result produced by the handler.
10661066
/// - Throws: Rethrows any error thrown by the handler or the underlying watch operation.
1067-
public func watchRequiredStringArray<Value: ${string_convertible_type["protocol"]} & Sendable, Return>(
1067+
public func watchRequiredStringArray<Value: ${string_convertible_type["protocol"]} & Sendable, Return: ~Copyable>(
10681068
forKey key: ConfigKey,
10691069
as type: Value.Type = Value.self,
10701070
isSecret: Bool = false,

Sources/Configuration/ConfigSnapshotReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ extension ConfigReader {
278278
/// - updatesHandler: A closure that receives an async sequence of `ConfigSnapshotReader` instances.
279279
/// - Returns: The value returned by the handler.
280280
/// - Throws: Any error thrown by the handler.
281-
public func watchSnapshot<Return>(
281+
public func watchSnapshot<Return: ~Copyable>(
282282
fileID: String = #fileID,
283283
line: UInt = #line,
284284
updatesHandler: (ConfigUpdatesAsyncSequence<ConfigSnapshotReader, Never>) async throws -> Return

Sources/Configuration/Deprecations.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ extension ConfigReader {
7272
/// - Returns: The value returned by the closure.
7373
/// - Throws: Rethrows any errors thrown by the provided closure.
7474
@available(*, deprecated, message: "Renamed to snapshot().")
75-
public func withSnapshot<Failure: Error, Return>(
75+
public func withSnapshot<Failure: Error, Return: ~Copyable>(
7676
_ body: (ConfigSnapshotReader) throws(Failure) -> Return
7777
) throws(Failure) -> Return {
7878
let multiSnapshot = provider.snapshot()

Sources/Configuration/MultiProvider.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ extension MultiProvider {
196196
/// - Returns: The value returned by the body closure.
197197
/// - Throws: Any error thrown by the nested providers or the body closure.
198198
nonisolated(nonsending)
199-
func watchSnapshot<Return>(
199+
func watchSnapshot<Return: ~Copyable>(
200200
_ body: (ConfigUpdatesAsyncSequence<MultiSnapshot, Never>) async throws -> Return
201201
) async throws -> Return
202202
{
@@ -287,7 +287,7 @@ extension MultiProvider {
287287
/// - Throws: Any error thrown by the nested providers or the handler closure.
288288
/// - Returns: The value returned by the handler.
289289
nonisolated(nonsending)
290-
func watchValue<Return>(
290+
func watchValue<Return: ~Copyable>(
291291
forKey key: AbsoluteConfigKey,
292292
type: ConfigType,
293293
updatesHandler: (
@@ -338,13 +338,13 @@ extension MultiProvider {
338338
}
339339

340340
@available(Configuration 1.0, *)
341-
nonisolated(nonsending) private func withProvidersWatchingValue<ReturnInner>(
341+
nonisolated(nonsending) private func withProvidersWatchingValue<Return: ~Copyable>(
342342
providers: ArraySlice<any ConfigProvider>,
343343
updateSequences: inout [any (AsyncSequence<Result<LookupResult, any Error>, Never> & Sendable)],
344344
key: AbsoluteConfigKey,
345345
configType: ConfigType,
346-
body: ([any (AsyncSequence<Result<LookupResult, any Error>, Never> & Sendable)]) async throws -> ReturnInner
347-
) async throws -> ReturnInner {
346+
body: ([any (AsyncSequence<Result<LookupResult, any Error>, Never> & Sendable)]) async throws -> Return
347+
) async throws -> Return {
348348
guard let provider = providers.first else {
349349
// Recursion termination, once we've collected all update sequences, execute the body.
350350
return try await body(updateSequences)
@@ -362,11 +362,11 @@ nonisolated(nonsending) private func withProvidersWatchingValue<ReturnInner>(
362362
}
363363

364364
@available(Configuration 1.0, *)
365-
nonisolated(nonsending) private func withProvidersWatchingSnapshot<ReturnInner>(
365+
nonisolated(nonsending) private func withProvidersWatchingSnapshot<Return: ~Copyable>(
366366
providers: ArraySlice<any ConfigProvider>,
367367
updateSequences: inout [any (AsyncSequence<any ConfigSnapshot, Never> & Sendable)],
368-
body: ([any (AsyncSequence<any ConfigSnapshot, Never> & Sendable)]) async throws -> ReturnInner
369-
) async throws -> ReturnInner {
368+
body: ([any (AsyncSequence<any ConfigSnapshot, Never> & Sendable)]) async throws -> Return
369+
) async throws -> Return {
370370
guard let provider = providers.first else {
371371
// Recursion termination, once we've collected all update sequences, execute the body.
372372
return try await body(updateSequences)

Sources/Configuration/Providers/CLI/CommandLineArgumentsProvider.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ extension CommandLineArgumentsProvider: ConfigProvider {
150150
}
151151

152152
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
153-
public func watchValue<Return>(
153+
public func watchValue<Return: ~Copyable>(
154154
forKey key: AbsoluteConfigKey,
155155
type: ConfigType,
156156
updatesHandler: (ConfigUpdatesAsyncSequence<Result<LookupResult, any Error>, Never>) async throws -> Return
@@ -164,7 +164,7 @@ extension CommandLineArgumentsProvider: ConfigProvider {
164164
}
165165

166166
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
167-
public func watchSnapshot<Return>(
167+
public func watchSnapshot<Return: ~Copyable>(
168168
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
169169
) async throws -> Return {
170170
try await watchSnapshotFromSnapshot(updatesHandler: updatesHandler)

Sources/Configuration/Providers/EnvironmentVariables/EnvironmentVariablesProvider.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ extension EnvironmentVariablesProvider: ConfigProvider {
486486
}
487487

488488
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
489-
public func watchValue<Return>(
489+
public func watchValue<Return: ~Copyable>(
490490
forKey key: AbsoluteConfigKey,
491491
type: ConfigType,
492492
updatesHandler: (ConfigUpdatesAsyncSequence<Result<LookupResult, any Error>, Never>) async throws -> Return
@@ -500,7 +500,7 @@ extension EnvironmentVariablesProvider: ConfigProvider {
500500
}
501501

502502
// swift-format-ignore: AllPublicDeclarationsHaveDocumentation
503-
public func watchSnapshot<Return>(
503+
public func watchSnapshot<Return: ~Copyable>(
504504
updatesHandler: (ConfigUpdatesAsyncSequence<any ConfigSnapshot, Never>) async throws -> Return
505505
) async throws -> Return {
506506
try await watchSnapshotFromSnapshot(updatesHandler: updatesHandler)

0 commit comments

Comments
 (0)