pub struct ExtractUtf8Error { /* private fields */ }
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§
Source§impl ExtractUtf8Error
impl ExtractUtf8Error
Sourcepub fn error_len(&self) -> usize
pub fn error_len(&self) -> usize
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.
Sourcepub fn into_extracted(self) -> StrChunk
pub fn into_extracted(self) -> StrChunk
Consumes self
to obtain the string content extracted up to
the encountered invalid sequence.
Trait Implementations§
Source§impl Clone for ExtractUtf8Error
impl Clone for ExtractUtf8Error
Source§fn clone(&self) -> ExtractUtf8Error
fn clone(&self) -> ExtractUtf8Error
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ExtractUtf8Error
impl Debug for ExtractUtf8Error
Source§impl Display for ExtractUtf8Error
impl Display for ExtractUtf8Error
Source§impl Error for ExtractUtf8Error
impl Error for ExtractUtf8Error
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl !Freeze for ExtractUtf8Error
impl RefUnwindSafe for ExtractUtf8Error
impl Send for ExtractUtf8Error
impl Sync for ExtractUtf8Error
impl Unpin for ExtractUtf8Error
impl UnwindSafe for ExtractUtf8Error
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more