pub struct Utf8Chunk<'a> { /* private fields */ }
Expand description
An item returned by the Utf8Chunks
iterator.
A Utf8Chunk
stores a sequence of u8
up to the first broken character
when decoding a UTF-8 string.
§Examples
// An invalid UTF-8 string
let bytes = b"foo\xF1\x80bar";
// Decode the first `Utf8Chunk`
let chunk = bytes.utf8_chunks().next().unwrap();
// The first three characters are valid UTF-8
assert_eq!("foo", chunk.valid());
// The fourth character is broken
assert_eq!(b"\xF1\x80", chunk.invalid());