[][src]Struct strchunk::ExtractUtf8Error

pub struct ExtractUtf8Error { /* fields omitted */ }

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

impl ExtractUtf8Error[src]

pub fn error_len(&self) -> usize[src]

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.

pub fn into_extracted(self) -> StrChunk[src]

Consumes self to obtain the string content extracted up to the encountered invalid sequence.

Trait Implementations

impl Clone for ExtractUtf8Error[src]

impl Debug for ExtractUtf8Error[src]

impl Display for ExtractUtf8Error[src]

impl Error for ExtractUtf8Error[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.