ThreadsafePooledIter

Struct ThreadsafePooledIter 

Source
pub struct ThreadsafePooledIter<I, BorrowedItem: ToOwned> { /* private fields */ }
Available on crate feature anchored-pool only.
Expand description

Convert a CursorLendingIterator into a CursorPooledIterator by storing recently accessed items in reusable buffers.

This effectively allows the iterator to lend out multiple items at once, unlike a lending iterator which can only lend out one. This comes primarily at the cost of extra copying into buffers, and in memory usage. The costs of allocating buffers is likely amortized by their reuse.

Implementations§

Source§

impl<I, BorrowedItem> ThreadsafePooledIter<I, BorrowedItem>
where BorrowedItem: ToOwned, BorrowedItem::Owned: Default,

Source

pub fn new(iter: I, num_buffers: usize) -> Self

Create a ThreadsafePooledIter that can lend out up to num_buffers items at a time.

Trait Implementations§

Source§

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

Source§

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

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

May need to wait for a buffer to become available.

§Potential Panics or Deadlocks

If self.buffer_pool_size() == 0, then this method panics. This method may also cause a deadlock if no buffers are currently available, and the current thread needs to make progress in order to release a buffer.

Source§

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

Move the iterator one position back, 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 panics. This method may also cause a deadlock if no buffers are currently available, and the current thread needs to make progress in order to release a buffer.

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.) Read more
Source§

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

If a buffer is available, get the current value the iterator is at, if the iterator is valid. Read more
Source§

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

If a buffer is available, move the iterator one position back, and return the entry at that position. Returns Ok(None) if the iterator was at the first entry. Read more
Source§

impl<I: Debug, BorrowedItem: Debug + ToOwned> Debug for ThreadsafePooledIter<I, BorrowedItem>
where BorrowedItem::Owned: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

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

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 panics. This method may also cause a deadlock if no buffers are currently available, and the current thread needs to make progress in order to release a buffer.

Source§

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

The item of this iterator, which likely has a nontrivial drop implementation that returns a buffer to the iterator’s buffer pool.
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. Read more
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. Read more
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. Read more
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. Read more
Source§

impl<I, BorrowedItem, Key, Cmp> Seekable<Key, Cmp> for ThreadsafePooledIter<I, BorrowedItem>
where I: CursorLendingIterator + Seekable<Key, Cmp>, BorrowedItem: ToOwned, Key: ?Sized, Cmp: Comparator<Key>, for<'lend> LentItem<'lend, I>: Borrow<BorrowedItem>,

Source§

fn reset(&mut self)

Reset the iterator to its initial position, before the first entry and after the last entry (if there are any entries in the collection). Read more
Source§

fn seek(&mut self, min_bound: &Key)

Move the iterator to the smallest key which is greater or equal than the provided min_bound. Read more
Source§

fn seek_before(&mut self, strict_upper_bound: &Key)

Move the iterator to the greatest key which is strictly less than the provided strict_upper_bound. Read more
Source§

fn seek_to_first(&mut self)

Move the iterator to the smallest key in the collection. Read more
Source§

fn seek_to_last(&mut self)

Move the iterator to the greatest key in the collection. Read more

Auto Trait Implementations§

§

impl<I, BorrowedItem> Freeze for ThreadsafePooledIter<I, BorrowedItem>
where I: Freeze,

§

impl<I, BorrowedItem> !RefUnwindSafe for ThreadsafePooledIter<I, BorrowedItem>

§

impl<I, BorrowedItem> Send for ThreadsafePooledIter<I, BorrowedItem>
where I: Send, <BorrowedItem as ToOwned>::Owned: Send,

§

impl<I, BorrowedItem> Sync for ThreadsafePooledIter<I, BorrowedItem>
where I: Sync, <BorrowedItem as ToOwned>::Owned: Send,

§

impl<I, BorrowedItem> Unpin for ThreadsafePooledIter<I, BorrowedItem>
where I: Unpin,

§

impl<I, BorrowedItem> !UnwindSafe for ThreadsafePooledIter<I, BorrowedItem>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> FragileContainer<T> for T
where T: ?Sized,

Source§

fn get_ref(&self) -> <T as FragileTryContainer<T>>::Ref<'_>

Infallibly get immutable access to the T.

Source§

impl<T> FragileMutContainer<T> for T
where T: ?Sized,

Source§

fn get_mut(&mut self) -> <T as FragileTryMutContainer<T>>::RefMut<'_>

Infallibly get mutable access to the T.

Source§

impl<T> FragileTryContainer<T> for T
where T: ?Sized,

Source§

fn into_inner(self) -> Option<T>

Infallibly get the T.

Source§

fn try_get_ref( &self, ) -> Result<<T as FragileTryContainer<T>>::Ref<'_>, <T as FragileTryContainer<T>>::RefError>

Infallibly get immutable access to the T.

Source§

type Ref<'a> = &'a T where T: 'a

An immutably borrowed value from the container. Read more
Source§

type RefError = Infallible

An error that might be returned by try_get_ref. This type should implement std::error::Error. Read more
Source§

fn new_container(t: T) -> T

Create a new container that owns the provided T.
Source§

impl<T> FragileTryMutContainer<T> for T
where T: ?Sized,

Source§

fn try_get_mut( &mut self, ) -> Result<<T as FragileTryMutContainer<T>>::RefMut<'_>, <T as FragileTryMutContainer<T>>::RefMutError>

Infallibly get mutable access to the T.

Source§

type RefMut<'a> = &'a mut T where T: 'a

A mutably borrowed value from the container. Read more
Source§

type RefMutError = Infallible

An error that might be returned by try_get_mut. This type should implement std::error::Error. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, C> BaseContainer<T> for C
where C: FragileTryContainer<T> + ?Sized, T: ?Sized,

Source§

impl<T, C> BaseMutContainer<T> for C
where C: FragileTryMutContainer<T> + ?Sized, T: ?Sized,

Source§

impl<T> Container<T> for T
where T: ?Sized,

Source§

impl<T> MutContainer<T> for T
where T: ?Sized,

Source§

impl<Key, Cmp, I> SeekablePooledIterator<Key, Cmp> for I
where Cmp: Comparator<Key> + ?Sized, I: CursorPooledIterator + Seekable<Key, Cmp>, Key: ?Sized,

Source§

impl<T> TryContainer<T> for T
where T: ?Sized,

Source§

impl<T> TryMutContainer<T> for T
where T: ?Sized,