Has anyone come up with generic interfaces for non-fallible sequential reading and writing of buffered UTF-8 data, similar to what
bytes::BufMut do for various byte buffers? On the writing side the most obvious recipient would be
String, but it should be possible to substitute a more efficient rope-like container for large texts, or a fixed-length string slice.
With the reading trait, it should be possible to:
- Borrow the next contiguous
strslice from the container.
- Advance the position to a valid index in the remaining UTF-8 sequence.
With the writing trait, it should be possible to:
- Append an
strslice after the current writing position.
- Unsafely borrow the next available buffer, preferably with capacity enough to hold any UTF-8 sequence, as a mutable byte slice.
- Unsafely commit a specified number of bytes in the buffer as the written UTF-8 sequence without checking for its validity.
The methods would not return
Result, but panic on any parameter errors like string indexing does. The writing container does not have to be expandable and the implementation may panic when it’s full.
Please let me know if there is a crate or a work in progress implementing something like this.