[−][src]Struct ringbuf::Consumer
Consumer part of ring buffer.
Implementations
impl<T: Sized> Consumer<T>
[src]
pub fn capacity(&self) -> usize
[src]
Returns capacity of the ring buffer.
The capacity of the buffer is constant.
pub fn is_empty(&self) -> bool
[src]
Checks if the ring buffer is empty.
The result may become irrelevant at any time because of concurring activity of the producer.
pub fn is_full(&self) -> bool
[src]
Checks if the ring buffer is full.
The result is relevant until you remove items from the consumer.
pub fn len(&self) -> usize
[src]
The length of the data stored in the buffer
Actual length may be equal to or greater than the returned value.
pub fn remaining(&self) -> usize
[src]
The remaining space in the buffer.
Actual remaining space may be equal to or less than the returning value.
pub fn access<F: FnOnce(&[T], &[T])>(&self, f: F)
[src]
Gives immutable access to the elements contained by the ring buffer without removing them.
The method takes a function f
as argument.
f
takes two slices of ring buffer content (the second one or both of them may be empty).
First slice contains older elements.
The slices may not include elements pushed to the buffer by concurring producer after the method call.
pub fn access_mut<F: FnOnce(&mut [T], &mut [T])>(&mut self, f: F)
[src]
Gives mutable access to the elements contained by the ring buffer without removing them.
The method takes a function f
as argument.
f
takes two slices of ring buffer content (the second one or both of them may be empty).
First slice contains older elements.
The iteration may not include elements pushed to the buffer by concurring producer after the method call.
pub unsafe fn pop_access<F>(&mut self, f: F) -> usize where
F: FnOnce(&mut [MaybeUninit<T>], &mut [MaybeUninit<T>]) -> usize,
[src]
F: FnOnce(&mut [MaybeUninit<T>], &mut [MaybeUninit<T>]) -> usize,
Allows to read from ring buffer memory directry.
This function is unsafe because it gives access to possibly uninitialized memory
The method takes a function f
as argument.
f
takes two slices of ring buffer content (the second one or both of them may be empty).
First slice contains older elements.
f
should return number of elements been read.
There is no checks for returned number - it remains on the developer's conscience.
The method always calls f
even if ring buffer is empty.
The method returns number returned from f
.
pub unsafe fn pop_copy(&mut self, elems: &mut [MaybeUninit<T>]) -> usize
[src]
Copies data from the ring buffer to the slice in byte-to-byte manner.
The elems
slice should contain un-initialized data before the method call.
After the call the copied part of data in elems
should be interpreted as initialized.
The remaining part is still un-iniitilized.
Returns the number of items been copied.
pub fn pop(&mut self) -> Option<T>
[src]
Removes latest element from the ring buffer and returns it.
Returns None
if the ring buffer is empty.
pub fn pop_each<F: FnMut(T) -> bool>(
&mut self,
f: F,
count: Option<usize>
) -> usize
[src]
&mut self,
f: F,
count: Option<usize>
) -> usize
Repeatedly calls the closure f
passing elements removed from the ring buffer to it.
The closure is called until it returns false
or the ring buffer is empty.
The method returns number of elements been removed from the buffer.
pub fn for_each<F: FnMut(&T)>(&self, f: F)
[src]
Iterate immutably over the elements contained by the ring buffer without removing them.
The iteration may not include elements pushed to the buffer by concurring producer after the method call.
pub fn for_each_mut<F: FnMut(&mut T)>(&mut self, f: F)
[src]
Iterate mutably over the elements contained by the ring buffer without removing them.
The iteration may not include elements pushed to the buffer by concurring producer after the method call.
pub fn discard(&mut self, n: usize) -> usize
[src]
Removes n
items from the buffer and safely drops them.
Returns the number of deleted items.
pub fn move_to(
&mut self,
other: &mut Producer<T>,
count: Option<usize>
) -> usize
[src]
&mut self,
other: &mut Producer<T>,
count: Option<usize>
) -> usize
Removes at most count
elements from the consumer and appends them to the producer.
If count
is None
then as much as possible elements will be moved.
The producer and consumer parts may be of different buffers as well as of the same one.
On success returns count of elements been moved.
impl<T: Sized + Copy> Consumer<T>
[src]
pub fn pop_slice(&mut self, elems: &mut [T]) -> usize
[src]
Removes first elements from the ring buffer and writes them into a slice.
Elements should be Copy
.
On success returns count of elements been removed from the ring buffer.
impl Consumer<u8>
[src]
pub fn write_into(
&mut self,
writer: &mut dyn Write,
count: Option<usize>
) -> Result<usize>
[src]
&mut self,
writer: &mut dyn Write,
count: Option<usize>
) -> Result<usize>
Removes at most first count
bytes from the ring buffer and writes them into
a Write
instance.
If count
is None
then as much as possible bytes will be written.
Returns Ok(n)
if write
is succeded. n
is number of bytes been written.
n == 0
means that either write
returned zero or ring buffer is empty.
If write
is failed then error is returned.
Trait Implementations
impl Read for Consumer<u8>
[src]
fn read(&mut self, buffer: &mut [u8]) -> Result<usize>
[src]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut]) -> Result<usize, Error>
1.36.0[src]
fn is_read_vectored(&self) -> bool
[src]
unsafe fn initializer(&self) -> Initializer
[src]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
1.0.0[src]
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
1.0.0[src]
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
1.6.0[src]
fn by_ref(&mut self) -> &mut Self
1.0.0[src]
fn bytes(self) -> Bytes<Self>
1.0.0[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0[src]
R: Read,
fn take(self, limit: u64) -> Take<Self>
1.0.0[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for Consumer<T>
impl<T> Send for Consumer<T> where
T: Send,
T: Send,
impl<T> Sync for Consumer<T> where
T: Send,
T: Send,
impl<T> Unpin for Consumer<T>
impl<T> !UnwindSafe for Consumer<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,