Trait async_ringbuf::traits::Consumer

pub trait Consumer: Observer {
Show 22 methods // Required method unsafe fn set_read_index(&self, value: usize); // Provided methods unsafe fn advance_read_index(&self, count: usize) { ... } fn occupied_slices( &self, ) -> (&[MaybeUninit<Self::Item>], &[MaybeUninit<Self::Item>]) { ... } unsafe fn occupied_slices_mut( &mut self, ) -> (&mut [MaybeUninit<Self::Item>], &mut [MaybeUninit<Self::Item>]) { ... } fn as_slices(&self) -> (&[Self::Item], &[Self::Item]) { ... } fn as_mut_slices(&mut self) -> (&mut [Self::Item], &mut [Self::Item]) { ... } fn first(&self) -> Option<&Self::Item> { ... } fn first_mut(&mut self) -> Option<&mut Self::Item> { ... } fn last(&self) -> Option<&Self::Item> { ... } fn last_mut(&mut self) -> Option<&mut Self::Item> { ... } fn try_pop(&mut self) -> Option<Self::Item> { ... } fn try_peek(&self) -> Option<&Self::Item> { ... } fn peek_slice_uninit(&self, elems: &mut [MaybeUninit<Self::Item>]) -> usize { ... } fn peek_slice(&self, elems: &mut [Self::Item]) -> usize where Self::Item: Copy { ... } fn pop_slice_uninit( &mut self, elems: &mut [MaybeUninit<Self::Item>], ) -> usize { ... } fn pop_slice(&mut self, elems: &mut [Self::Item]) -> usize where Self::Item: Copy { ... } fn pop_iter(&mut self) -> PopIter<'_, Self> { ... } fn iter(&self) -> Chain<Iter<'_, Self::Item>, Iter<'_, Self::Item>> { ... } fn iter_mut( &mut self, ) -> Chain<IterMut<'_, Self::Item>, IterMut<'_, Self::Item>> { ... } fn skip(&mut self, count: usize) -> usize { ... } fn clear(&mut self) -> usize { ... } fn write_into<S>( &mut self, writer: &mut S, count: Option<usize>, ) -> Option<Result<usize, Error>> where S: Write, Self: Consumer<Item = u8> { ... }
}
Expand description

Consumer part of ring buffer.

Required Methods§

unsafe fn set_read_index(&self, value: usize)

Set read index.

§Safety

Index must go only forward, never backward. It is recommended to use Self::advance_read_index instead.

All slots with index less than value must be uninitialized until write index, all slots with index equal or greater - must be initialized.

Provided Methods§

unsafe fn advance_read_index(&self, count: usize)

Moves read pointer by count places forward.

§Safety

First count items in occupied memory must be moved out or dropped.

Must not be called concurrently.

fn occupied_slices( &self, ) -> (&[MaybeUninit<Self::Item>], &[MaybeUninit<Self::Item>])

Provides a direct access to the ring buffer occupied memory. The difference from Self::as_slices is that this method provides slices of MaybeUninit, so items may be moved out of slices.

Returns a pair of slices of stored items, the second one may be empty. Elements with lower indices in slice are older. First slice contains older items that second one.

§Safety

All items are initialized. Elements must be removed starting from the beginning of first slice. When all items are removed from the first slice then items must be removed from the beginning of the second slice.

This method must be followed by Self::advance_read_index call with the number of items being removed previously as argument. No other mutating calls allowed before that.

unsafe fn occupied_slices_mut( &mut self, ) -> (&mut [MaybeUninit<Self::Item>], &mut [MaybeUninit<Self::Item>])

Provides a direct mutable access to the ring buffer occupied memory.

Same as Self::occupied_slices.

§Safety

When some item is replaced with uninitialized value then it must not be read anymore.

fn as_slices(&self) -> (&[Self::Item], &[Self::Item])

Returns a pair of slices which contain, in order, the contents of the ring buffer.

fn as_mut_slices(&mut self) -> (&mut [Self::Item], &mut [Self::Item])

Returns a pair of mutable slices which contain, in order, the contents of the ring buffer.

fn first(&self) -> Option<&Self::Item>

Returns a reference to the eldest item in the ring buffer, if exists.

fn first_mut(&mut self) -> Option<&mut Self::Item>

Returns a mutable reference to the eldest item in the ring buffer, if exists.

fn last(&self) -> Option<&Self::Item>

Returns a reference to the most recent item in the ring buffer, if exists.

Returned item may not be actually the most recent if there is a concurrent producer activity.

fn last_mut(&mut self) -> Option<&mut Self::Item>

Returns a mutable reference to the most recent item in the ring buffer, if exists.

Returned item may not be actually the most recent if there is a concurrent producer activity.

fn try_pop(&mut self) -> Option<Self::Item>

Removes the eldest item from the ring buffer and returns it.

Returns None if the ring buffer is empty.

fn try_peek(&self) -> Option<&Self::Item>

Returns the reference to the eldest item without removing it from the buffer.

Returns None if the ring buffer is empty.

fn peek_slice_uninit(&self, elems: &mut [MaybeUninit<Self::Item>]) -> usize

Copies items from the ring buffer to an uninit slice without removing them from the ring buffer.

Returns a number of items being copied.

fn peek_slice(&self, elems: &mut [Self::Item]) -> usize
where Self::Item: Copy,

Copies items from the ring buffer to a slice without removing them from the ring buffer.

Returns a number of items being copied.

fn pop_slice_uninit(&mut self, elems: &mut [MaybeUninit<Self::Item>]) -> usize

Removes items from the ring buffer and writes them into an uninit slice.

Returns count of items been removed.

fn pop_slice(&mut self, elems: &mut [Self::Item]) -> usize
where Self::Item: Copy,

Removes items from the ring buffer and writes them into a slice.

Returns count of items been removed.

fn pop_iter(&mut self) -> PopIter<'_, Self>

Returns an iterator that removes items one by one from the ring buffer.

fn iter(&self) -> Chain<Iter<'_, Self::Item>, Iter<'_, Self::Item>>

Returns a front-to-back iterator containing references to items in the ring buffer.

This iterator does not remove items out of the ring buffer.

fn iter_mut( &mut self, ) -> Chain<IterMut<'_, Self::Item>, IterMut<'_, Self::Item>>

Returns a front-to-back iterator that returns mutable references to items in the ring buffer.

This iterator does not remove items out of the ring buffer.

fn skip(&mut self, count: usize) -> usize

Removes at most count and at least min(count, Self::len()) items from the buffer and safely drops them.

If there is no concurring producer activity then exactly min(count, Self::len()) items are removed.

Returns the number of deleted items.

let mut rb = LocalRb::<Array<i32, 8>>::default();

assert_eq!(rb.push_iter(0..8), 8);

assert_eq!(rb.skip(4), 4);
assert_eq!(rb.skip(8), 4);
assert_eq!(rb.skip(4), 0);

fn clear(&mut self) -> usize

Removes all items from the buffer and safely drops them.

Returns the number of deleted items.

fn write_into<S>( &mut self, writer: &mut S, count: Option<usize>, ) -> Option<Result<usize, Error>>
where S: Write, Self: Consumer<Item = u8>,

Removes at most first count bytes from the ring buffer and writes them into a Write instance. If count is None then as much as possible bytes will be written.

Returns:

  • None: ring buffer is full or count is 0. In this case write isn’t called at all.
  • Some(Ok(n)): write succeeded. n is number of bytes been written. n == 0 means that write also returned 0.
  • Some(Err(e)): write is failed and e is original error. In this case it is guaranteed that no items was written to the writer. To achieve this we write only one contiguous slice at once. So this call may write less than occupied_len items even if the writer is ready to get more.

Object Safety§

This trait is not object safe.

Implementors§

§

impl<D> Consumer for D
where D: DelegateConsumer, <D as Based>::Base: Consumer,

§

impl<R> Consumer for Caching<R, false, true>
where R: RbRef,

§

impl<R> Consumer for Direct<R, false, true>
where R: RbRef,

§

impl<R> Consumer for Frozen<R, false, true>
where R: RbRef,

§

impl<S> Consumer for LocalRb<S>
where S: Storage + ?Sized,

§

impl<S> Consumer for SharedRb<S>
where S: Storage + ?Sized,

source§

impl<S: Storage> Consumer for AsyncRb<S>