pub trait Consumer: Observer {
Show 14 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 try_pop(&mut self) -> Option<Self::Item> { ... } fn pop_slice(&mut self, elems: &mut [Self::Item]) -> usize where Self::Item: Copy { ... } fn pop_iter(&mut self) -> PopIter<&mut Self, Self> where Self: AsMut<Self> + AsRef<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§

source

unsafe fn set_read_index(&self, value: usize)

Provided Methods§

source

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.

source

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] call with the number of items being removed previously as argument. No other mutating calls allowed before that.

source

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.

source

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

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

source

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.

source

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

Removes latest item from the ring buffer and returns it.

Returns None if the ring buffer is empty.

source

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

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

Returns count of items been removed.

source

fn pop_iter(&mut self) -> PopIter<&mut Self, Self>where Self: AsMut<Self> + AsRef<Self>,

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

source

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.

source

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.

source

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::<Static<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);
source

fn clear(&mut self) -> usize

Removes all items from the buffer and safely drops them.

Returns the number of deleted items.

source

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.

Implementors§

source§

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

source§

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

source§

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

source§

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

source§

impl<S> Consumer for LocalRb<S>where S: Storage,

source§

impl<S> Consumer for SharedRb<S>where S: Storage,

source§

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