Why don't UTF8Views conform to RangeReplaceableCollection?

RangeReplaceableCollection unfortunately does not support situations where the collection can temporarily be in an invalid state before an eventual validation. RRC conformance would add append(_:UInt8) to the UTF8View, and validation would convert this to U+FFFD for every byte of a multi-byte scalar. An alternative approach could be something like a closure (or coroutine) that allows you to append bytes and only does the error correction at the very end.

I wrote much more about this here: String Mutations

12 Likes