CursorLendingIterator

Trait CursorLendingIterator 

Source
pub trait CursorLendingIterator: for<'a> LendItem<'a> {
    // Required methods
    fn valid(&self) -> bool;
    fn next(&mut self) -> Option<LentItem<'_, Self>>;
    fn current(&self) -> Option<LentItem<'_, Self>>;
    fn prev(&mut self) -> Option<LentItem<'_, Self>>;

    // Provided methods
    fn into_lender(self) -> LenderAdapter<Self>
       where Self: Sized { ... }
    fn into_lending_iterator(self) -> LendingIteratorAdapter<Self>
       where Self: Sized { ... }
}
Expand description

A CursorLendingIterator provides access to the entries of some sorted collection, and can move its current position in either direction.

As a lending iterator, only one entry can be accessed at a time.

Conceptually, it is circular, and its initial position is before the first entry and after the last entry. As such, it is not a FusedIterator, as continuing to call next() at the end of iteration wraps around to the start. (Note that if the collection is empty, then the iterator will remain at that phantom position.)

Implementations may or may not be threadsafe. Even if an implementation is threadsafe, newly-added entries may or may not be seen immediately by other threads.

Forwards iteration should be preferred over backwards iteration.

Required Methods§

Source

fn valid(&self) -> bool

Determine whether the iterator is currently at any value in the collection. If the iterator is invalid, then it is conceptually one position before the first entry and one position after the last entry. (Or, there may be no entries.)

current() will be Some if and only if the iterator is valid.

Source

fn next(&mut self) -> Option<LentItem<'_, Self>>

Move the iterator one position forwards, and return the entry at that position. Returns None if the iterator was at the last entry.

Source

fn current(&self) -> Option<LentItem<'_, Self>>

Get the current value the iterator is at, if the iterator is valid.

Source

fn prev(&mut self) -> Option<LentItem<'_, Self>>

Move the iterator one position back, and return the entry at that position. Returns None if the iterator was at the first entry.

Some implementations may have worse performance for backwards iteration than forwards iteration, so prefer to not use prev.

Provided Methods§

Source

fn into_lender(self) -> LenderAdapter<Self>
where Self: Sized,

Available on crate feature lender only.

Convert the CursorLendingIterator into a lender::Lender lending iterator.

The seekability and access to cursor methods are preserved, though none of the Cursor*Iterator or Seekable*Iterator traits are implemented for the adaptor, in order to avoid conflicts with the next() method name.

Source

fn into_lending_iterator(self) -> LendingIteratorAdapter<Self>
where Self: Sized,

Available on crate feature lending-iterator only.

Convert the CursorLendingIterator into a lending_iterator::LendingIterator.

The seekability and access to cursor methods are preserved, though none of the Cursor*Iterator or Seekable*Iterator traits are implemented for the adaptor, in order to avoid conflicts with the next() method name.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Key, Cmp, Iter> CursorLendingIterator for MergingIter<Key, Cmp, Iter>
where Key: ?Sized, Cmp: Comparator<Key>, Iter: SeekableLendingIterator<Key, Cmp> + ItemToKey<Key>,

Available on crate feature alloc only.