async_ringbuf::traits::consumer

Trait AsyncConsumer

Source
pub trait AsyncConsumer: Consumer {
    // Required methods
    fn register_waker(&self, waker: &Waker);
    fn close(&mut self);

    // Provided methods
    fn is_closed(&self) -> bool { ... }
    fn pop(&mut self) -> PopFuture<'_, Self>  { ... }
    fn wait_occupied(&mut self, count: usize) -> WaitOccupiedFuture<'_, Self>  { ... }
    fn pop_exact<'a: 'b, 'b>(
        &'a mut self,
        slice: &'b mut [Self::Item],
    ) -> PopSliceFuture<'a, 'b, Self> 
       where Self::Item: Copy { ... }
    fn pop_until_end<'a: 'b, 'b>(
        &'a mut self,
        vec: &'b mut Vec<Self::Item>,
    ) -> PopVecFuture<'a, 'b, Self>  { ... }
    fn poll_next(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
    ) -> Poll<Option<Self::Item>>
       where Self: Unpin { ... }
    fn poll_read(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &mut [u8],
    ) -> Poll<Result<usize>>
       where Self: AsyncConsumer<Item = u8> + Unpin { ... }
}

Required Methods§

Source

fn register_waker(&self, waker: &Waker)

Source

fn close(&mut self)

Provided Methods§

Source

fn is_closed(&self) -> bool

Whether the corresponding producer was closed.

Source

fn pop(&mut self) -> PopFuture<'_, Self>

Pop item from the ring buffer waiting asynchronously if the buffer is empty.

Future returns:

  • Some(item) - an item is taken.
  • None - the buffer is empty and the corresponding producer was dropped.
Source

fn wait_occupied(&mut self, count: usize) -> WaitOccupiedFuture<'_, Self>

Wait for the buffer to contain at least count items or to close.

In debug mode panics if count is greater than buffer capacity.

The method takes &mut self because only single WaitOccupiedFuture is allowed at a time.

Source

fn pop_exact<'a: 'b, 'b>( &'a mut self, slice: &'b mut [Self::Item], ) -> PopSliceFuture<'a, 'b, Self>
where Self::Item: Copy,

Pop item from the ring buffer waiting asynchronously if the buffer is empty.

Future returns:

  • Ok - the whole slice is filled with the items from the buffer.
  • Err(count) - the buffer is empty and the corresponding producer was dropped, number of items copied to slice is returned.
Source

fn pop_until_end<'a: 'b, 'b>( &'a mut self, vec: &'b mut Vec<Self::Item>, ) -> PopVecFuture<'a, 'b, Self>

Source

fn poll_next( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Option<Self::Item>>
where Self: Unpin,

Source

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8], ) -> Poll<Result<usize>>
where Self: AsyncConsumer<Item = u8> + Unpin,

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§