[pitch] Add `Span`-providing Properties to Standard Library Types

Your previous proposal had:

extension String {
  var utf8Span: UTF8Span { _read }
}

extension Substring {
  var utf8Span: UTF8Span { _read }
}

extension UTF8Span {
  var storage: Span<UInt8> { get }
}

Your current proposal has:

extension String.UTF8View {
  var storage: Span<Element> { get }
  var bytes: RawSpan { get }
}

extension Substring.UTF8View {
  var storage: Span<Element> { get }
  var bytes: RawSpan { get }
}

If UTF8Span is still planned, should it be considered as an alternative?


Could the bytes property be moved alongside the existing withUnsafeBytes method?

extension Span where Element: BitwiseCopyable {
  var bytes: RawSpan { get }
}

For example:

  • myString.utf8.storage.bytes
  • myString.utf8.storage.withUnsafeBytes { … }

Should EmptyCollection and StaticString be included in this proposal?