Skip to main content

FallibleIterator

Trait FallibleIterator 

Source
pub trait FallibleIterator {
    type Item;
    type Error: Error;

    // Required method
    fn next(&mut self) -> Result<Option<Self::Item>, Self::Error>;

    // Provided method
    fn collect<B>(self) -> Result<B, Self::Error>
       where B: FromIterator<Self::Item>,
             Self: Sized { ... }
}
Expand description

Variation of the Iterator trait where each read can fail.

Required Associated Types§

Source

type Item

Type of items returned by this iterator.

Source

type Error: Error

Type of errors that can occur when reading from this iterator.

Required Methods§

Source

fn next(&mut self) -> Result<Option<Self::Item>, Self::Error>

Advances the iterator and returns the next value.

§Errors

May fail depending on the implementation.

Provided Methods§

Source

fn collect<B>(self) -> Result<B, Self::Error>
where B: FromIterator<Self::Item>, Self: Sized,

Transforms an iterator into a collection.

§Errors

This consumes the iterator and reads from it. If any read fails, the result is the first error encountered.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§