PooledIterator

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;

    // Provided methods
    fn into_lender(self) -> PooledLenderAdapter<Self>
       where Self: Sized { ... }
    fn into_lending_iterator(self) -> PooledLendingIteratorAdapter<Self>
       where Self: Sized { ... }
}
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 is permitted to panic or deadlock. This method may also panic or cause a deadlock if no buffers are currently available, and the current thread needs to make progress in order to release a buffer.

If it is possible for a different thread to make progress and make a buffer available, this method should not 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.

Provided Methods§

Source

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

Available on crate feature lender only.

Convert the PooledIterator into a lender::Lender lending iterator which only uses one buffer at a time.

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.

§Potential Panics or Deadlocks

If self.buffer_pool_size() == 0, then methods of the returned iterator might panic or deadlock.

Source

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

Available on crate feature lending-iterator only.

Convert the PooledIterator into a lending_iterator::LendingIterator which only uses one buffer at a time.

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.

§Potential Panics or Deadlocks

If self.buffer_pool_size() == 0, then methods of the returned iterator might panic or deadlock.

Implementors§

Source§

impl<I, BorrowedItem> PooledIterator for PooledIter<I, BorrowedItem>
where I: CursorLendingIterator, BorrowedItem: ToOwned, for<'lend> LentItem<'lend, I>: Borrow<BorrowedItem>,

Available on crate feature anchored-pool only.
Source§

type Item = PoolItem<<BorrowedItem as ToOwned>::Owned>

Source§

impl<I, BorrowedItem> PooledIterator for ThreadsafePooledIter<I, BorrowedItem>
where I: CursorLendingIterator, BorrowedItem: ToOwned, for<'lend> LentItem<'lend, I>: Borrow<BorrowedItem>,

Available on crate feature anchored-pool only.
Source§

type Item = ThreadsafePoolItem<<BorrowedItem as ToOwned>::Owned>