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§
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 try_peek(&self) -> Option<&Self::Item>
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.
Sourcefn peek_slice_uninit(&self, elems: &mut [MaybeUninit<Self::Item>]) -> usize
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.
Sourcefn peek_slice(&self, elems: &mut [Self::Item]) -> usize
fn peek_slice(&self, elems: &mut [Self::Item]) -> usize
Copies items from the ring buffer to a slice without removing them from the ring buffer.
Returns a number of items being copied.
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<'_, Self> ⓘ
fn pop_iter(&mut self) -> PopIter<'_, 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.
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.