Trait PooledIterator

Source
pub trait PooledIterator {
    type Item;

    // Required methods
    fn next(&mut self) -> Option<Self::Item>;
    fn try_next(&mut self) -> Result<Option<Self::Item>, OutOfBuffers>;
    fn buffer_pool_size(&self) -> usize;
    fn available_buffers(&self) -> usize;
}
Expand description

A PooledIterator is similar to a lending iterator (which can lend one item at a time), but can make use of a buffer pool to lend out multiple items at a time.

Implementations may or may not be threadsafe. Even if an implementation is threadsafe, items newly-added to the backing collection of the iterator may or may not be seen immediately by other threads.

Required Associated Types§

Source

type Item

The item of this iterator, which likely has a nontrivial drop implementation that returns a buffer to the iterator’s buffer pool.

Required Methods§

Source

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

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

May need to wait for a buffer to become available.

§Potential Panics or Deadlocks

If self.buffer_pool_size() == 0, then this method may panic or deadlock.

Source

fn try_next(&mut self) -> Result<Option<Self::Item>, OutOfBuffers>

If a buffer is available, move the iterator one position forwards, and return the entry at that position. Returns Ok(None) if the iterator was at the last entry.

§Errors

Returns an error if no buffers were available.

Source

fn buffer_pool_size(&self) -> usize

Get the total number of buffers in the buffer pool, including buffers that are currently in use.

Source

fn available_buffers(&self) -> usize

Get the number of buffers that are currently available.

In multithreaded scenarios, the returned value could change at any time.

Implementors§