Skip to content

Commit 9cdd83b

Browse files
committed
[stdlib] add span properties to UnsafeBufferPointer family
1 parent 85b53bb commit 9cdd83b

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

stdlib/public/core/UnsafeBufferPointer.swift.gyb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -564,6 +564,16 @@ extension Unsafe${Mutable}BufferPointer where Element: ~Copyable {
564564
public func extracting(_ bounds: UnboundedRange) -> Self {
565565
unsafe self
566566
}
567+
568+
@available(SwiftStdlib 6.2, *)
569+
public var span: Span<Element> {
570+
@lifetime(borrow self)
571+
@_alwaysEmitIntoClient
572+
get {
573+
let span = Span(_unsafeElements: self)
574+
return _overrideLifetime(span, borrowing: self)
575+
}
576+
}
567577
}
568578

569579
extension Unsafe${Mutable}BufferPointer {

stdlib/public/core/UnsafeRawBufferPointer.swift.gyb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -1171,6 +1171,16 @@ extension Unsafe${Mutable}RawBufferPointer {
11711171
try unsafe body(${ 'UnsafeBufferPointer<Element>($0)' if Mutable else '$0' })
11721172
}
11731173
}
1174+
1175+
@available(SwiftStdlib 6.2, *)
1176+
public var bytes: RawSpan {
1177+
@lifetime(borrow self)
1178+
@_alwaysEmitIntoClient
1179+
get {
1180+
let span = RawSpan(_unsafeBytes: self)
1181+
return _overrideLifetime(span, borrowing: self)
1182+
}
1183+
}
11741184
}
11751185

11761186
@_unavailableInEmbedded

0 commit comments

Comments
 (0)