ringbuf::traits::observer

Trait Observer

Source
pub trait Observer {
    type Item: Sized;

    // Required methods
    fn capacity(&self) -> NonZeroUsize;
    fn read_index(&self) -> usize;
    fn write_index(&self) -> usize;
    unsafe fn unsafe_slices(
        &self,
        start: usize,
        end: usize,
    ) -> (&[MaybeUninit<Self::Item>], &[MaybeUninit<Self::Item>]);
    unsafe fn unsafe_slices_mut(
        &self,
        start: usize,
        end: usize,
    ) -> (&mut [MaybeUninit<Self::Item>], &mut [MaybeUninit<Self::Item>]);
    fn read_is_held(&self) -> bool;
    fn write_is_held(&self) -> bool;

    // Provided methods
    fn occupied_len(&self) -> usize { ... }
    fn vacant_len(&self) -> usize { ... }
    fn is_empty(&self) -> bool { ... }
    fn is_full(&self) -> bool { ... }
}
Expand description

Ring buffer observer.

Can observe ring buffer state but cannot safely access its data.

Required Associated Types§

Required Methods§

Source

fn capacity(&self) -> NonZeroUsize

Capacity of the ring buffer.

It is constant during the whole ring buffer lifetime.

Source

fn read_index(&self) -> usize

Index of the last item in the ring buffer.

Index value is in range 0..(2 * capacity).

Source

fn write_index(&self) -> usize

Index of the next empty slot in the ring buffer.

Index value is in range 0..(2 * capacity).

Source

unsafe fn unsafe_slices( &self, start: usize, end: usize, ) -> (&[MaybeUninit<Self::Item>], &[MaybeUninit<Self::Item>])

Get slice between start and end indices.

§Safety

Slice must not overlap with any mutable slice existing at the same time.

Non-Sync items must not be accessed from multiple threads at the same time.

Source

unsafe fn unsafe_slices_mut( &self, start: usize, end: usize, ) -> (&mut [MaybeUninit<Self::Item>], &mut [MaybeUninit<Self::Item>])

Get mutable slice between start and end indices.

§Safety

There must not exist overlapping slices at the same time.

Source

fn read_is_held(&self) -> bool

Whether read end is held by consumer.

Source

fn write_is_held(&self) -> bool

Whether write end is held by producer.

Provided Methods§

Source

fn occupied_len(&self) -> usize

The number of items stored in the buffer.

Actual number may be greater or less than returned value due to concurring activity of producer or consumer respectively.

Source

fn vacant_len(&self) -> usize

The number of remaining free places in the buffer.

Actual number may be greater or less than returned value due to concurring activity of consumer or producer respectively.

Source

fn is_empty(&self) -> bool

Checks if the ring buffer is empty.

The result may become irrelevant at any time because of concurring producer activity.

Source

fn is_full(&self) -> bool

Checks if the ring buffer is full.

The result may become irrelevant at any time because of concurring consumer activity.

Implementors§

Source§

impl<D: DelegateObserver> Observer for D
where D::Base: Observer,

Source§

type Item = <<D as Based>::Base as Observer>::Item

Source§

impl<R: RbRef, const P: bool, const C: bool> Observer for Caching<R, P, C>

Source§

type Item = <<R as RbRef>::Rb as Observer>::Item

Source§

impl<R: RbRef, const P: bool, const C: bool> Observer for Direct<R, P, C>

Source§

type Item = <<R as RbRef>::Rb as Observer>::Item

Source§

impl<R: RbRef, const P: bool, const C: bool> Observer for Frozen<R, P, C>

Source§

type Item = <<R as RbRef>::Rb as Observer>::Item

Source§

impl<S: Storage + ?Sized> Observer for LocalRb<S>

Source§

type Item = <S as Storage>::Item

Source§

impl<S: Storage + ?Sized> Observer for SharedRb<S>

Source§

type Item = <S as Storage>::Item