async_ringbuf::traits

Trait Observer

pub trait Observer {
    type Item;

    // Required methods
    fn capacity(&self) -> NonZero<usize>;
    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§

type Item

Required Methods§

fn capacity(&self) -> NonZero<usize>

Capacity of the ring buffer.

It is constant during the whole ring buffer lifetime.

fn read_index(&self) -> usize

Index of the last item in the ring buffer.

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

fn write_index(&self) -> usize

Index of the next empty slot in the ring buffer.

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

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.

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.

fn read_is_held(&self) -> bool

Whether read end is held by consumer.

fn write_is_held(&self) -> bool

Whether write end is held by producer.

Provided Methods§

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.

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.

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.

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§

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

type Item = <S as Storage>::Item

§

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

§

type Item = <S as Storage>::Item

Source§

impl<S: Storage> Observer for AsyncRb<S>

Source§

type Item = <S as Storage>::Item