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

Ring buffer read end.

Provides access to occupied memory and mechanism of item extraction.

It is recommended not to use this trait directly. Use Producer and Consumer instead.

Required Methods§

source

unsafe fn set_head(&self, value: usize)

Sets the new head position.

Safety

This call must cohere with ring buffer data modification.

It is recommended to use Self::advance_head instead.

Provided Methods§

source

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.

source

fn occupied_ranges(&self) -> (Range<usize>, Range<usize>)

Returns a pair of ranges of Self::occupied_slices location in underlying container.

source

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.

source

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 is Some(count) then exactly count items will be removed. In debug mode panics if count is greater than number of items stored in the buffer.
  • If count_or_all is None 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.

Implementors§

source§

impl<T, C: Container<T>> RbRead<T> for LocalRb<T, C>

source§

impl<T, C: Container<T>> RbRead<T> for SharedRb<T, C>

source§

impl<T, R: RbRef> RbRead<T> for RbReadCache<T, R>where R::Rb: RbRead<T>,