[][src]Enum rustf8::Utf8IteratorError

pub enum Utf8IteratorError {
    IoError(ErrorBox<[u8]>),
    InvalidSequenceError(Box<[u8]>),
    LongSequenceError(Box<[u8]>),
    InvalidCharError(Box<[u8]>),
}

The Utf8Iterator will identify UTF-8 decoding errors returning the enum Utf8IteratorError.

The error will also contain a Box<u8> with the malformed sequence.

Example

 fn next_token (chiter: &mut Utf8Iterator<Bytes<Cursor<&str>>>, state: &mut (State, Token))
   -> Option<Token> {
     loop {
         let r = chiter.next();
         match r {
             Some(item) => match item {
                 Ok(ch) => {
                     *state = state_machine(chiter, ch, &state);
                     if let State::FinishedToken = state.0 {
                         return Some(state.1.clone());
                     }
                 }
                 Err(e) => match e {
                     InvalidSequenceError(bytes) => {
                         panic!("Detected an invalid UTF-8 sequence! {:?}", bytes)
                     }
                     LongSequenceError(bytes) => {
                         panic!("UTF-8 sequence with more tha 4 bytes! {:?}", bytes)
                     }
                     InvalidCharError(bytes) => panic!(
                         "UTF-8 sequence resulted in an invalid character! {:?}",
                         bytes
                     ),
                     IoError(ioe, bytes) => panic!(
                         "I/O error {:?} while decoding de sequence {:?} !",
                         ioe, bytes
                     ),
                 },
             },
             None => {
                 if let State::Finalized = state.0 {
                     return None;
                 } else {
                     state.0 = State::Finalized;
                     return Some(state.1.clone());
                 }
             }
         }
     }
 };
   

Variants

IoError(ErrorBox<[u8]>)

Returns the IO error coming from the underling iterator wrapped by Utf8Iterator.

The error std::io::ErrorKind::Interrupted is consumed by the iterator and is not returned.

InvalidSequenceError(Box<[u8]>)

The decoder found a malformed sequence.

LongSequenceError(Box<[u8]>)

The sequence is well formed, but it is too long (more than 4 bytes).

InvalidCharError(Box<[u8]>)

Found a well formed UTF-8 sequence, nevertheless the value does not represent a valid character.

Trait Implementations

impl Debug for Utf8IteratorError[src]

impl Display for Utf8IteratorError[src]

impl Error for Utf8IteratorError[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> 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.