Trait async_ringbuf::traits::Consumer
source · pub trait Consumer: Observer {
Show 19 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 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<&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§
sourceunsafe fn set_read_index(&self, value: usize)
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§
sourceunsafe fn advance_read_index(&self, count: usize)
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.
sourcefn occupied_slices(
&self
) -> (&[MaybeUninit<Self::Item>], &[MaybeUninit<Self::Item>])
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.
sourceunsafe fn occupied_slices_mut(
&mut self
) -> (&mut [MaybeUninit<Self::Item>], &mut [MaybeUninit<Self::Item>])
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.
sourcefn as_slices(&self) -> (&[Self::Item], &[Self::Item])
fn as_slices(&self) -> (&[Self::Item], &[Self::Item])
Returns a pair of slices which contain, in order, the contents of the ring buffer.
sourcefn as_mut_slices(&mut self) -> (&mut [Self::Item], &mut [Self::Item])
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.
sourcefn first(&self) -> Option<&Self::Item>
fn first(&self) -> Option<&Self::Item>
Returns a reference to the eldest item in the ring buffer, if exists.
sourcefn first_mut(&mut self) -> Option<&mut Self::Item>
fn first_mut(&mut self) -> Option<&mut Self::Item>
Returns a mutable reference to the eldest item in the ring buffer, if exists.
sourcefn last(&self) -> Option<&Self::Item>
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.
sourcefn last_mut(&mut self) -> Option<&mut Self::Item>
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.
sourcefn try_pop(&mut self) -> Option<Self::Item>
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.
sourcefn pop_slice_uninit(&mut self, elems: &mut [MaybeUninit<Self::Item>]) -> usize
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.
sourcefn pop_slice(&mut self, elems: &mut [Self::Item]) -> usize
fn pop_slice(&mut self, elems: &mut [Self::Item]) -> usize
Removes items from the ring buffer and writes them into a slice.
Returns count of items been removed.
sourcefn pop_iter(&mut self) -> PopIter<&mut Self, Self>
fn pop_iter(&mut self) -> PopIter<&mut Self, Self>
Returns an iterator that removes items one by one from the ring buffer.
sourcefn iter(&self) -> Chain<Iter<'_, Self::Item>, Iter<'_, Self::Item>>
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.
sourcefn iter_mut(
&mut self
) -> Chain<IterMut<'_, Self::Item>, IterMut<'_, Self::Item>>
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.
sourcefn skip(&mut self, count: usize) -> usize
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);sourcefn clear(&mut self) -> usize
fn clear(&mut self) -> usize
Removes all items from the buffer and safely drops them.
Returns the number of deleted items.
sourcefn write_into<S>(
&mut self,
writer: &mut S,
count: Option<usize>
) -> Option<Result<usize, Error>>
fn write_into<S>( &mut self, writer: &mut S, count: Option<usize> ) -> Option<Result<usize, Error>>
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 orcountis0. In this casewriteisn’t called at all.Some(Ok(n)):writesucceeded.nis number of bytes been written.n == 0means thatwritealso returned0.Some(Err(e)):writeis failed andeis 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 thanoccupied_lenitems even if the writer is ready to get more.