Skip to main content

AsyncConsumer

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.
§Cancel safety

If future is cancelled then no item removed from the ring buffer.

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.

§Cancel safety

The future can be safely cancelled.

Source

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

Fill slice with items from the ring buffer waiting asynchronously until slice filled or corresponding producer closed.

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.
§Cancel safety

If future is cancelled then slice can be partially filled. The number of items already copied can be examined by PopSliceFuture::count.

Source

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

Fill vec with items from the ring buffer waiting asynchronously until corresponding producer closed.

§Cancel safety

If future is cancelled then vec contains items taken from RB before cancellation.

Source

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

Poll for the next item in the ring buffer.

Source

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

Poll reading bytes from byte buffer.

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§