Trait rb::RbConsumer
[−]
[src]
pub trait RbConsumer<T> { fn skip_pending(&self) -> Result<usize>; fn skip(&self, cnt: usize) -> Result<usize>; fn get(&self, _: &mut [T]) -> Result<usize>; fn read(&self, _: &mut [T]) -> Result<usize>; fn read_blocking(&self, _: &mut [T]) -> Option<usize>; }
Defines read methods for a consumer view.
Required Methods
fn skip_pending(&self) -> Result<usize>
Skips all pending values. Technically it sets the read pointer of the producer to the position of the conumers write pointer.
Returns the number of skipped elements.
Possible errors:
RbError::Empty
no pending elements
fn skip(&self, cnt: usize) -> Result<usize>
Skips cnt
number of elements.
Returns the number of skipped elements.
Possible errors:
RbError::Empty
no pending elements
fn get(&self, _: &mut [T]) -> Result<usize>
Fills the given slice with values or, if the buffer is empty, does not modify it.
This method does not change the state of the buffer, this means that the read pointer
isn't changed if you call get
. Consecutive calls to this method are idempotent, i.e. they
will fill the given slice with the same data.
Using get
can be beneficial to read
when a successive call has failed and you want to
try again with same data. You can use skip
to move the read pointer i.e. mark the values
as read after the call succeeded.
Returns the number of written values or an error.
Possible errors:
- RbError::Empty
fn read(&self, _: &mut [T]) -> Result<usize>
Fills the given slice with values or, if the buffer is empty, does not modify it. Returns the number of written values or an error.
Possible errors:
- RbError::Empty
fn read_blocking(&self, _: &mut [T]) -> Option<usize>
Works analog to read
but blocks until it can read enough elements to fill
the given buffer slice.
Returns None
if the given slice has zero length.