pub struct RingBufferConsumer<T, PW: OptionalWaiter, CW: OptionalWaiter> { /* private fields */ }Expand description
Consumer side of the ring buffer.
Implementations§
Source§impl<T, PW: OptionalWaiter, CW: OptionalWaiter> RingBufferConsumer<T, PW, CW>
impl<T, PW: OptionalWaiter, CW: OptionalWaiter> RingBufferConsumer<T, PW, CW>
Sourcepub fn pop(&mut self) -> Result<Option<T>, ClosedError<()>>
pub fn pop(&mut self) -> Result<Option<T>, ClosedError<()>>
Tries to pop an item from the buffer.
Returns Ok(Some(_)) if the buffer had an item, Ok(None) if
the buffer was empty but the sender is still available, or Err(ClosedError(()))
if the buffer is empty and the sender had been dropped.
Sourcepub fn view(&mut self) -> Result<ReadView<'_, T, PW, CW>, ClosedError<()>>
pub fn view(&mut self) -> Result<ReadView<'_, T, PW, CW>, ClosedError<()>>
Gets a view into the currently readable portion of this ring buffer.
This returns a wrapper over two slices, which, when concatenated, form the
available space in order. The user should read the items, then call
ReadView::consume or ReadView::consume_all to remove the items
from the buffer.
If the buffer is empty and the sender had been dropped, returns
Err(ClosedError(())).
This can be used, for example, to write bytes directly from the ring buffer, via
std::io::Write::write_all, without having to use another buffer.
Sourcepub fn available_len(&self) -> usize
pub fn available_len(&self) -> usize
Gets how many items that can be read.
If the producer side is being used on another thread, the actual amount may increase after this function has returned.
Source§impl<T, PW: OptionalWaiter, CW> RingBufferConsumer<T, PW, CW>where
CW: for<'a> Waiter<'a> + OptionalWaiter,
impl<T, PW: OptionalWaiter, CW> RingBufferConsumer<T, PW, CW>where
CW: for<'a> Waiter<'a> + OptionalWaiter,
Sourcepub fn wait<'a>(&'a mut self) -> <CW as Waiter<'a>>::Future
pub fn wait<'a>(&'a mut self) -> <CW as Waiter<'a>>::Future
Waits for an item to be produced into the buffer, or for the producer to be closed.
This method is only available if the buffer was created with a producer waker.
How the wait happens is up to the waiter - it may block, return a future, etc. Ideally, it should return immediately if space is already available.
Source§impl<T: Copy, PW: OptionalWaiter, CW: OptionalWaiter> RingBufferConsumer<T, PW, CW>
impl<T: Copy, PW: OptionalWaiter, CW: OptionalWaiter> RingBufferConsumer<T, PW, CW>
Sourcepub fn pop_to_slice(&mut self, dest: &mut [T]) -> Result<usize, ClosedError<()>>
pub fn pop_to_slice(&mut self, dest: &mut [T]) -> Result<usize, ClosedError<()>>
Pops as many items as possible, copying them into a destination slice.
Returns the amount of items copied, which may be zero.