Trait ringbuf::ring_buffer::RbRead
source · pub trait RbRead<T>: RbBase<T> {
// Required method
unsafe fn set_head(&self, value: usize);
// Provided methods
unsafe fn advance_head(&self, count: usize) { ... }
fn occupied_ranges(&self) -> (Range<usize>, Range<usize>) { ... }
unsafe fn occupied_slices(
&self
) -> (&mut [MaybeUninit<T>], &mut [MaybeUninit<T>]) { ... }
unsafe fn skip_internal(&self, count_or_all: Option<usize>) -> usize { ... }
}
Expand description
Required Methods§
Provided Methods§
sourceunsafe fn advance_head(&self, count: usize)
unsafe fn advance_head(&self, count: usize)
Move head position by count
items forward.
Safety
First count
items in occupied area must be initialized before this call.
In debug mode panics if count
is greater than number of items in the ring buffer.
sourcefn occupied_ranges(&self) -> (Range<usize>, Range<usize>)
fn occupied_ranges(&self) -> (Range<usize>, Range<usize>)
Returns a pair of ranges of Self::occupied_slices
location in underlying container.
sourceunsafe fn occupied_slices(
&self
) -> (&mut [MaybeUninit<T>], &mut [MaybeUninit<T>])
unsafe fn occupied_slices( &self ) -> (&mut [MaybeUninit<T>], &mut [MaybeUninit<T>])
Provides a direct mutable access to the ring buffer occupied memory.
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_head
call with the number of items being removed previously as argument.
No other mutating calls allowed before that.
sourceunsafe fn skip_internal(&self, count_or_all: Option<usize>) -> usize
unsafe fn skip_internal(&self, count_or_all: Option<usize>) -> usize
Removes items from the head of ring buffer and drops them.
- If
count_or_all
isSome(count)
then exactlycount
items will be removed. In debug mode panics ifcount
is greater than number of items stored in the buffer. - If
count_or_all
isNone
then all items in ring buffer will be removed. If there is concurring producer activity then the buffer may be not empty after this call.
Returns the number of removed items.
Safety
Must not be called concurrently.