Trait ringbuf::traits::observer::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,

§

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>

§

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>

§

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>

§

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

source§

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

§

type Item = <S as Storage>::Item

source§

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

§

type Item = <S as Storage>::Item