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§
Required Methods§
Sourcefn next(&mut self) -> Option<Self::Item>
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.
Sourcefn try_next(&mut self) -> Result<Option<Self::Item>, OutOfBuffers>
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.
Sourcefn buffer_pool_size(&self) -> usize
fn buffer_pool_size(&self) -> usize
Get the total number of buffers in the buffer pool, including buffers that are currently in use.
Sourcefn available_buffers(&self) -> usize
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.