Trait async_ringbuf::traits::Producer
source · pub trait Producer: Observer {
// Required method
unsafe fn set_write_index(&self, value: usize);
// Provided methods
unsafe fn advance_write_index(&self, count: usize) { ... }
fn vacant_slices(
&self
) -> (&[MaybeUninit<Self::Item>], &[MaybeUninit<Self::Item>]) { ... }
fn vacant_slices_mut(
&mut self
) -> (&mut [MaybeUninit<Self::Item>], &mut [MaybeUninit<Self::Item>]) { ... }
fn try_push(&mut self, elem: Self::Item) -> Result<(), Self::Item> { ... }
fn push_iter<I>(&mut self, iter: I) -> usize
where I: Iterator<Item = Self::Item> { ... }
fn push_slice(&mut self, elems: &[Self::Item]) -> usize
where Self::Item: Copy { ... }
fn read_from<S>(
&mut self,
reader: &mut S,
count: Option<usize>
) -> Option<Result<usize, Error>>
where S: Read,
Self: Producer<Item = u8> { ... }
}Expand description
Producer part of ring buffer.
Required Methods§
sourceunsafe fn set_write_index(&self, value: usize)
unsafe fn set_write_index(&self, value: usize)
Set read index.
§Safety
Index must go only forward, never backward. It is recommended to use Self::advance_write_index instead.
All slots with index less than value must be initialized until write index, all slots with index equal or greater - must be uninitialized.
Provided Methods§
sourceunsafe fn advance_write_index(&self, count: usize)
unsafe fn advance_write_index(&self, count: usize)
Moves write pointer by count places forward.
§Safety
First count items in free space must be initialized.
Must not be called concurrently.
sourcefn vacant_slices(
&self
) -> (&[MaybeUninit<Self::Item>], &[MaybeUninit<Self::Item>])
fn vacant_slices( &self ) -> (&[MaybeUninit<Self::Item>], &[MaybeUninit<Self::Item>])
Provides a direct access to the ring buffer vacant memory.
Returns a pair of slices of uninitialized memory, the second one may be empty.
sourcefn vacant_slices_mut(
&mut self
) -> (&mut [MaybeUninit<Self::Item>], &mut [MaybeUninit<Self::Item>])
fn vacant_slices_mut( &mut self ) -> (&mut [MaybeUninit<Self::Item>], &mut [MaybeUninit<Self::Item>])
Mutable version of Self::vacant_slices.
Vacant memory is uninitialized. Initialized items must be put starting from the beginning of first slice. When first slice is fully filled then items must be put to the beginning of the second slice.
This method must be followed by Self::advance_write_index call with the number of items being put previously as argument.
No other mutating calls allowed before that.
Vacant slices must not be used to store any data because their contents aren’t synchronized properly.
sourcefn try_push(&mut self, elem: Self::Item) -> Result<(), Self::Item>
fn try_push(&mut self, elem: Self::Item) -> Result<(), Self::Item>
Appends an item to the ring buffer.
If buffer is full returns an Err containing the item that hasn’t been appended.
sourcefn push_iter<I>(&mut self, iter: I) -> usize
fn push_iter<I>(&mut self, iter: I) -> usize
Appends items from an iterator to the ring buffer. Elements that haven’t been added to the ring buffer remain in the iterator.
Returns count of items been appended to the ring buffer.
Inserted items are committed to the ring buffer all at once in the end, e.g. when buffer is full or iterator has ended.
sourcefn push_slice(&mut self, elems: &[Self::Item]) -> usize
fn push_slice(&mut self, elems: &[Self::Item]) -> usize
Appends items from slice to the ring buffer.
Returns count of items been appended to the ring buffer.
sourcefn read_from<S>(
&mut self,
reader: &mut S,
count: Option<usize>
) -> Option<Result<usize, Error>>
fn read_from<S>( &mut self, reader: &mut S, count: Option<usize> ) -> Option<Result<usize, Error>>
Reads at most count bytes from Read instance and appends them to the ring buffer.
If count is None then as much as possible bytes will be read.
Returns:
None: ring buffer is empty orcountis0. In this casereadisn’t called at all.Some(Ok(n)):readsucceeded.nis number of bytes been read.n == 0means thatreadalso returned0.Some(Err(e))readis failed andeis original error. In this case it is guaranteed that no items was read from the reader. To achieve this we read only one contiguous slice at once. So this call may read less thanvacant_lenitems in the buffer even if the reader is ready to provide more.