Trait mz_repr::row::iter::RowIterator

source ·
pub trait RowIterator: Debug {
    // Required methods
    fn next(&mut self) -> Option<&RowRef>;
    fn peek(&mut self) -> Option<&RowRef>;
    fn count(&self) -> usize;

    // Provided method
    fn map<T, F>(self, f: F) -> MappedRowIterator<Self, F> 
       where Self: Sized,
             F: FnMut(&RowRef) -> T { ... }
}
Expand description

An iterator that can borrow from self and yield RowRefs.

This trait is a “lending iterator” for Rows, in other words, an iterator that borrows from self (e.g. an underlying memory buffer) to return a RowRef. The std::iter::Iterator trait does not currently support this pattern because there is no way to name the lifetime of the borrow on its associated Item type. Generic Associated Types (GATs) would allow this but so far no new trait has been introduced with this API.

There are a few open source crates that provide a trait:

Neither have an IntoLendingIterator trait that is useful for our interface, nor do they work well with trait objects.

Required Methods§

source

fn next(&mut self) -> Option<&RowRef>

Returns the next RowRef advancing the iterator.

source

fn peek(&mut self) -> Option<&RowRef>

Returns the next RowRef without advancing the iterator.

source

fn count(&self) -> usize

The total number of Rows this iterator could ever yield.

Note: it does not return the number of rows remaining, in otherwords calling .next() will not change the value returned from this method.

Provided Methods§

source

fn map<T, F>(self, f: F) -> MappedRowIterator<Self, F>
where Self: Sized, F: FnMut(&RowRef) -> T,

Maps the returned RowRefs from this RowIterator.

Implementations on Foreign Types§

source§

impl<I: RowIterator + ?Sized> RowIterator for &mut I

source§

fn next(&mut self) -> Option<&RowRef>

source§

fn peek(&mut self) -> Option<&RowRef>

source§

fn count(&self) -> usize

source§

impl<I: RowIterator + ?Sized> RowIterator for Box<I>

source§

fn next(&mut self) -> Option<&RowRef>

source§

fn peek(&mut self) -> Option<&RowRef>

source§

fn count(&self) -> usize

Implementors§