Skip to content

Commit eaf74ac

Browse files
committed
[span] add missing RawSpan initializers
1 parent fafd9d3 commit eaf74ac

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

stdlib/public/core/Span/RawSpan.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ extension RawSpan {
141141
self.init(_unsafeBytes: UnsafeRawBufferPointer(buffer))
142142
}
143143

144+
/// Unsafely create a `RawSpan` over initialized memory.
145+
///
146+
/// The memory in `buffer` must be valid and initialized
147+
/// for at least as long as the returned `RawSpan` exists.
148+
///
149+
/// - Parameters:
150+
/// - buffer: a raw buffer to initialized memory.
151+
@_disallowFeatureSuppression(NonescapableTypes)
152+
@_alwaysEmitIntoClient
153+
@lifetime(immortal)
154+
public init<T: BitwiseCopyable>(
155+
_unsafeElements buffer: borrowing Slice<UnsafeBufferPointer<T>>
156+
) {
157+
self.init(
158+
_unsafeBytes: .init(UnsafeBufferPointer(rebasing: buffer))
159+
)
160+
}
161+
144162
/// Unsafely create a `RawSpan` over initialized memory.
145163
///
146164
/// The memory in `buffer` must be owned by the instance `owner`,
@@ -159,6 +177,24 @@ extension RawSpan {
159177
self.init(_unsafeElements: UnsafeBufferPointer(buffer))
160178
}
161179

180+
/// Unsafely create a `RawSpan` over initialized memory.
181+
///
182+
/// The memory in `buffer` must be valid and initialized
183+
/// for at least as long as the returned `RawSpan` exists.
184+
///
185+
/// - Parameters:
186+
/// - buffer: a raw buffer to initialized memory.
187+
@_disallowFeatureSuppression(NonescapableTypes)
188+
@_alwaysEmitIntoClient
189+
@lifetime(immortal)
190+
public init<T: BitwiseCopyable>(
191+
_unsafeElements buffer: borrowing Slice<UnsafeMutableBufferPointer<T>>
192+
) {
193+
self.init(
194+
_unsafeBytes: .init(UnsafeBufferPointer(rebasing: buffer))
195+
)
196+
}
197+
162198
/// Unsafely create a `RawSpan` over initialized memory.
163199
///
164200
/// The memory over `count` bytes starting at

0 commit comments

Comments
 (0)