Skip to content

Commit e5fa401

Browse files
committed
A few more updates, and omissions remedied
1 parent 5585bc6 commit e5fa401

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

proposals/nnnn-outputspan.md

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ extension OutputSpan where Element: ~Copyable {
273273

274274
`OutputSpan` also provides the ability to access its individual initialized elements by index:
275275
```swift
276-
extension OutputSpan wehre Element: ~Copyable {
276+
extension OutputSpan where Element: ~Copyable {
277277
/// The type that represents an initialized position in an `OutputSpan`.
278278
typealias Index = Int
279279

@@ -448,6 +448,10 @@ extension OutputRawSpan {
448448
The basic operation is to append the bytes of some value to an `OutputRawSpan`. Note that since the fundamental operation is appending bytes, `OutputRawSpan` does not concern itself with memory alignment.
449449
```swift
450450
extension OutputRawSpan {
451+
/// Append a single byte to this span
452+
@lifetime(self: copy self)
453+
public mutating func append(_ value: UInt8)
454+
451455
/// Appends the given value's bytes to this span's initialized bytes
452456
@lifetime(self: copy self)
453457
public mutating func append<T: BitwiseCopyable>(
@@ -522,6 +526,29 @@ extension OutputRawSpan {
522526
}
523527
```
524528
529+
Methods to deinitialize memory from an `OutputRawSpan`:
530+
531+
```swift
532+
extension OutputRawSpan {
533+
534+
/// Remove the last byte from this span
535+
@lifetime(self: copy self)
536+
public mutating func removeLast() -> UInt8 {
537+
538+
/// Remove the last N elements, returning the memory they occupy
539+
/// to the uninitialized state.
540+
///
541+
/// `n` must not be greater than `count`
542+
@lifetime(self: copy self)
543+
public mutating func removeLast(_ n: Int)
544+
545+
/// Remove all this span's elements and return its memory
546+
/// to the uninitialized state.
547+
@lifetime(self: copy self)
548+
public mutating func removeAll()
549+
}
550+
```
551+
525552

526553
##### Interoperability with unsafe code
527554

@@ -825,10 +852,6 @@ This proposal considers the naming of `OutputSpan`'s bulk-copying methods more c
825852

826853
```swift
827854
extension MutableSpan where Element: Copyable {
828-
public mutating func update(
829-
from source: inout some IteratorProtocol<Element>
830-
) -> Index
831-
832855
public mutating func update(
833856
fromContentsOf source: some Sequence<Element>
834857
) -> Index
@@ -856,17 +879,17 @@ extension MutableSpan {
856879
public mutating func append(
857880
consuming source: Slice<UnsafeMutableBufferPointer<Element>>
858881
)
882+
883+
public mutating func update(
884+
from source: inout some IteratorProtocol<Element>
885+
) -> Index
859886
}
860887
```
861888

862889
Similarly, `MutableRawSpan`'s bulk-copying methods would be replaced by the following:
863890

864891
```swift
865892
extension MutableRawSpan {
866-
public mutating func update<T: BitwiseCopyable>(
867-
from source: inout some IteratorProtocol<T>, as type: T.Type
868-
) -> Index
869-
870893
public mutating func update<T: BitwiseCopyable>(
871894
fromContentsOf source: some Sequence<T>, as type: T.Type
872895
) -> Index
@@ -882,6 +905,10 @@ extension MutableRawSpan {
882905
public mutating func append(
883906
fromContentsOf source: UnsafeRawBufferPointer
884907
) -> Index
908+
909+
public mutating func update<T: BitwiseCopyable>(
910+
from source: inout some IteratorProtocol<T>, as type: T.Type
911+
) -> Index
885912
}
886913
```
887914

@@ -995,8 +1022,8 @@ We could expand upon this ability to disambiguate by using keywords or even new
9951022
let buffer: UnsafeMutableBufferPointer<MyType> = ...
9961023
let array = Array(capacity: buffer.count*2) {
9971024
(o: inout OutputSpan<MyType>) in
998-
o.append(contentsOf: borrowing buffer)
999-
o.append(contentsOf: consuming buffer)
1025+
o.append(contentsOf: borrow buffer)
1026+
o.append(contentsOf: consume buffer)
10001027
}
10011028
```
10021029

0 commit comments

Comments
 (0)