Struct strchunk::ExtractUtf8Error [−][src]
pub struct ExtractUtf8Error { /* fields omitted */ }
Expand description
An error returned by StrChunk::extract_utf8
.
ExtractUtf8Error
indicates an invalid UTF-8 sequence encountered
in the input and provides information necessary for lossy recovery
of an incremental UTF-8 decoding stream.
Example
const TEST_DATA: &[u8] = b"Hello \xF0\x90\x80World";
let mut input = BytesMut::from(TEST_DATA);
let err = StrChunk::extract_utf8(&mut input).unwrap_err();
input.advance(err.error_len());
let chunk1 = err.into_extracted();
assert_eq!(chunk1, "Hello ");
// Can inject a replacement character into the output, e.g. U+FFFD
let chunk2 = StrChunk::extract_utf8(&mut input).unwrap();
assert_eq!(chunk2, "World");
Implementations
Length of the invalid byte sequence.
A lossy decoding procedure should advance the reading position
by the returned amount using the advance
method of the input buffer
to resume decoding.
Consumes self
to obtain the string content extracted up to
the encountered invalid sequence.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for ExtractUtf8Error
impl Send for ExtractUtf8Error
impl Sync for ExtractUtf8Error
impl Unpin for ExtractUtf8Error
impl UnwindSafe for ExtractUtf8Error
Blanket Implementations
Mutably borrows from an owned value. Read more