Skip to content

Commit 7722c84

Browse files
committed
[stdlib] add withContiguousStorage to CollectionOfOne
1 parent 9f51c06 commit 7722c84

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

stdlib/public/core/CollectionOfOne.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ extension CollectionOfOne.Iterator: IteratorProtocol {
7070
}
7171
}
7272

73+
extension CollectionOfOne: Sequence {
74+
@inlinable // trivial-implementation
75+
public func withContiguousStorageIfAvailable<R>(
76+
_ body: (UnsafeBufferPointer<Element>) throws -> R
77+
) rethrows -> R? {
78+
return try withUnsafePointer(to: _element) {
79+
let buf = UnsafeBufferPointer(start: $0, count: 1)
80+
return try body(buf)
81+
}
82+
}
83+
}
84+
7385
extension CollectionOfOne: RandomAccessCollection, MutableCollection {
7486

7587
public typealias Index = Int

0 commit comments

Comments
 (0)