Skip to main content

FallibleIteratorMut

Trait FallibleIteratorMut 

Source
pub trait FallibleIteratorMut {
    type Item;
    type Error;

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

    // Provided methods
    fn size_hint(&self) -> (usize, Option<usize>) { ... }
    fn map<F, B>(&mut self, f: F) -> Map<'_, Self, F>
       where Self: Sized,
             F: FnMut(&mut Self::Item) -> Result<B, Self::Error> { ... }
}
Expand description

Provides a FallibleIterator over mutable references.

Ordinarily a FallibleIterator iterates over owned items, which makes this trait incompatible with it. The map method allows converting this trait into a FallibleIterator, and it’s also possible to use with a while let loop:

use sqlite3_ext::FallibleIteratorMut;

fn dump<I: FallibleIteratorMut>(mut it: I) -> Result<(), I::Error>
where
    I::Item: std::fmt::Debug,
{
    while let Some(x) = it.next()? {
        println!("{:?}", x);
    }
    Ok(())
}

Required Associated Types§

Source

type Item

The type of item being iterated.

Source

type Error

The type of error that can be returned by this iterator.

Required Methods§

Source

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

Works like FallibleIterator::next, except instead of returning Self::Item, it returns &mut Self::Item.

Provided Methods§

Source

fn size_hint(&self) -> (usize, Option<usize>)

Source

fn map<F, B>(&mut self, f: F) -> Map<'_, Self, F>
where Self: Sized, F: FnMut(&mut Self::Item) -> Result<B, Self::Error>,

Convert this iterator into a FallibleIterator by applying a function to each element.

Implementors§