@@ -516,7 +516,7 @@ extension StructuredFieldValueParser {
516516 throw StructuredHeaderError . invalidDisplayString
517517 }
518518
519- let octetHex = EncodedHex ( ArraySlice ( self . underlyingData. prefix ( 2 ) ) )
519+ let octetHex = EncodedHex ( self . underlyingData. prefix ( 2 ) )
520520
521521 self . underlyingData = self . underlyingData. dropFirst ( 2 )
522522
@@ -557,13 +557,10 @@ extension StructuredFieldValueParser {
557557 // String(validatingUTF8:) requires byteArray to be null-terminated.
558558 byteArray. append ( 0 )
559559
560- let unicodeSequence = try byteArray. withUnsafeBytes {
561- try $0. withMemoryRebound ( to: CChar . self) {
562- guard let baseAddress = $0. baseAddress else {
563- throw StructuredHeaderError . invalidDisplayString
564- }
565-
566- return String ( validatingUTF8: baseAddress)
560+ let unicodeSequence = byteArray. withUnsafeBytes {
561+ $0. withMemoryRebound ( to: CChar . self) {
562+ // This force-unwrap is safe, as the buffer must successfully bind to CChar.
563+ String ( validatingUTF8: $0. baseAddress!)
567564 }
568565 }
569566
@@ -732,10 +729,10 @@ struct EncodedHex {
732729 private( set) var firstChar : UInt8
733730 private( set) var secondChar : UInt8
734731
735- init ( _ slice : ArraySlice < UInt8 > ) {
736- precondition ( slice . count == 2 )
737- self . firstChar = slice [ slice . startIndex]
738- self . secondChar = slice [ slice . index ( after: slice . startIndex) ]
732+ init < Bytes : RandomAccessCollection > ( _ bytes : Bytes ) where Bytes . Element == UInt8 {
733+ precondition ( bytes . count == 2 )
734+ self . firstChar = bytes [ bytes . startIndex]
735+ self . secondChar = bytes [ bytes . index ( after: bytes . startIndex) ]
739736 }
740737
741738 /// Validates and converts `EncodedHex` to a base 10 UInt8.
0 commit comments