Skip to main content

AsyncProducer

Trait AsyncProducer 

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

    // Provided methods
    fn is_closed(&self) -> bool { ... }
    fn push(&mut self, item: Self::Item) -> PushFuture<'_, Self> ⓘ { ... }
    fn push_iter_all<I: Iterator<Item = Self::Item>>(
        &mut self,
        iter: I,
    ) -> PushIterFuture<'_, Self, I> ⓘ { ... }
    fn wait_vacant(&mut self, count: usize) -> WaitVacantFuture<'_, Self> ⓘ { ... }
    fn push_exact<'a: 'b, 'b>(
        &'a mut self,
        slice: &'b [Self::Item],
    ) -> PushSliceFuture<'a, 'b, Self> ⓘ
       where Self::Item: Copy { ... }
    fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<bool> { ... }
    fn poll_write(
        self: Pin<&mut Self>,
        cx: &mut Context<'_>,
        buf: &[u8],
    ) -> Poll<Result<usize>>
       where Self: AsyncProducer<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 consumer was closed.

Source

fn push(&mut self, item: Self::Item) -> PushFuture<'_, Self> ⓘ

Push item to the ring buffer waiting asynchronously if the buffer is full.

Future returns:

  • Ok - item successfully pushed.
  • Err(item) - the corresponding consumer was dropped, item is returned back.
§Cancel safety

If future is cancelled no item pushed to the RB.

Source

fn push_iter_all<I: Iterator<Item = Self::Item>>( &mut self, iter: I, ) -> PushIterFuture<'_, Self, I> ⓘ

Push items from iterator waiting asynchronously if the buffer is full.

Future returns:

  • true - iterator ended.
  • false - the corresponding consumer was dropped.
§Cancel safety

If future is cancelled then remaining items are left in iterator. You can get the iterator by using PushIterFuture::inner, PushIterFuture::inner_mut and PushIterFuture::into_inner. Note that the iterator is Peekable.

Source

fn wait_vacant(&mut self, count: usize) -> WaitVacantFuture<'_, Self> ⓘ

Wait for the buffer to have at least count free places for items or to close.

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

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

§Cancel safety

You can safely cancel this future.

Source

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

Copy slice contents to the buffer waiting asynchronously if the buffer is full.

Future returns:

  • Ok - all slice contents are copied.
  • Err(count) - the corresponding consumer was dropped, number of copied items returned.
§Cancel safety

On cancel the slice can be copied partially. The number of items already copied can be examined by PushSliceFuture::count.

Source

fn poll_ready(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<bool>

Poll the ring buffer has free slot for at least one item and the corresponding consumer is not closed.

Source

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

Poll writing bytes into byte buffer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§