RingBufferConsumer

Struct RingBufferConsumer 

Source
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>

Source

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.

Source

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.

Source

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

pub fn capacity(&self) -> usize

Returns the maximum number of elements that the buffer can hold.

Source§

impl<T, PW: OptionalWaiter, CW> RingBufferConsumer<T, PW, CW>
where CW: for<'a> Waiter<'a> + OptionalWaiter,

Source

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

pub fn waiter(&mut self) -> &CW

Gets the waiter.

Can be used to alter settings of the waiter, for example, by setting a timeout.

Source§

impl<T: Copy, PW: OptionalWaiter, CW: OptionalWaiter> RingBufferConsumer<T, PW, CW>

Source

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.

Trait Implementations§

Source§

impl<T, PW: OptionalWaiter, CW: OptionalWaiter> Drop for RingBufferConsumer<T, PW, CW>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T, PW, CW> Freeze for RingBufferConsumer<T, PW, CW>

§

impl<T, PW, CW> RefUnwindSafe for RingBufferConsumer<T, PW, CW>

§

impl<T, PW, CW> Send for RingBufferConsumer<T, PW, CW>
where T: Send,

§

impl<T, PW, CW> Sync for RingBufferConsumer<T, PW, CW>
where T: Send,

§

impl<T, PW, CW> Unpin for RingBufferConsumer<T, PW, CW>

§

impl<T, PW, CW> UnwindSafe for RingBufferConsumer<T, PW, CW>

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> 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.