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§
Sourcefn capacity(&self) -> NonZeroUsize
fn capacity(&self) -> NonZeroUsize
Capacity of the ring buffer.
It is constant during the whole ring buffer lifetime.
Sourcefn read_index(&self) -> usize
fn read_index(&self) -> usize
Index of the last item in the ring buffer.
Index value is in range 0..(2 * capacity)
.
Sourcefn write_index(&self) -> usize
fn write_index(&self) -> usize
Index of the next empty slot in the ring buffer.
Index value is in range 0..(2 * capacity)
.
Sourceunsafe fn unsafe_slices(
&self,
start: usize,
end: usize,
) -> (&[MaybeUninit<Self::Item>], &[MaybeUninit<Self::Item>])
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.
Sourceunsafe fn unsafe_slices_mut(
&self,
start: usize,
end: usize,
) -> (&mut [MaybeUninit<Self::Item>], &mut [MaybeUninit<Self::Item>])
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.
Sourcefn read_is_held(&self) -> bool
fn read_is_held(&self) -> bool
Whether read end is held by consumer.
Sourcefn write_is_held(&self) -> bool
fn write_is_held(&self) -> bool
Whether write end is held by producer.
Provided Methods§
Sourcefn occupied_len(&self) -> usize
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.
Sourcefn vacant_len(&self) -> usize
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.