diff --git a/Sources/ContainersPreview/Protocols/Producer+Collect.swift b/Sources/ContainersPreview/Protocols/Producer+Collect.swift new file mode 100644 index 00000000..c1b68566 --- /dev/null +++ b/Sources/ContainersPreview/Protocols/Producer+Collect.swift @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift Collections open source project +// +// Copyright (c) 2026 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// +// SPDX-License-Identifier: Apache-2.0 WITH Swift-exception +// +//===----------------------------------------------------------------------===// + +#if compiler(>=6.2) && COLLECTIONS_UNSTABLE_CONTAINERS_PREVIEW + +@available(SwiftStdlib 5.0, *) +extension Producer where Self: ~Copyable & ~Escapable { + @inlinable + public consuming func collect>( + into container: R.Type = R.self + ) throws(ProducerError) -> R { + try R(from: &self) + } + + @inlinable + public consuming func collect( + into container: inout some DynamicContainer + ) throws(ProducerError) { + try container.append(from: &self) + } +} + +#endif diff --git a/Sources/ContainersPreview/Protocols/Producer.swift b/Sources/ContainersPreview/Protocols/Producer.swift index e15e4f92..fd42f475 100644 --- a/Sources/ContainersPreview/Protocols/Producer.swift +++ b/Sources/ContainersPreview/Protocols/Producer.swift @@ -274,21 +274,4 @@ extension Producer where Self: ~Copyable & ~Escapable { } } -@available(SwiftStdlib 5.0, *) -extension Producer where Self: ~Copyable & ~Escapable { - @inlinable - public consuming func collect>( - into container: R.Type = R.self - ) throws(ProducerError) -> R { - try R(from: &self) - } - - @inlinable - public consuming func collect( - into container: inout some DynamicContainer - ) throws(ProducerError) { - try container.append(from: &self) - } -} - #endif