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§
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 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.
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.
Provided Methods§
Sourcefn into_lender(self) -> PooledLenderAdapter<Self>where
Self: Sized,
Available on crate feature lender only.
fn into_lender(self) -> PooledLenderAdapter<Self>where
Self: Sized,
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.
Sourcefn into_lending_iterator(self) -> PooledLendingIteratorAdapter<Self>where
Self: Sized,
Available on crate feature lending-iterator only.
fn into_lending_iterator(self) -> PooledLendingIteratorAdapter<Self>where
Self: Sized,
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.
impl<I, BorrowedItem> PooledIterator for PooledIter<I, BorrowedItem>where
I: CursorLendingIterator,
BorrowedItem: ToOwned,
for<'lend> LentItem<'lend, I>: Borrow<BorrowedItem>,
anchored-pool only.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.
impl<I, BorrowedItem> PooledIterator for ThreadsafePooledIter<I, BorrowedItem>where
I: CursorLendingIterator,
BorrowedItem: ToOwned,
for<'lend> LentItem<'lend, I>: Borrow<BorrowedItem>,
anchored-pool only.