Struct bytes::RingBuf
[−]
[src]
pub struct RingBuf { // some fields omitted }
Buf backed by a continous chunk of memory. Maintains a read cursor and a write cursor. When reads and writes reach the end of the allocated buffer, wraps around to the start.
This type is suited for use cases where reads and writes are intermixed.
Methods
impl RingBuf
fn new(capacity: usize) -> RingBuf
Allocates a new RingBuf
with the specified capacity.
fn is_full(&self) -> bool
Returns true
if the buf cannot accept any further writes.
fn is_empty(&self) -> bool
Returns true
if the buf cannot accept any further reads.
fn capacity(&self) -> usize
Returns the number of bytes that the buf can hold.
fn mark(&mut self)
Marks the current read location.
Together with reset
, this can be used to read from a section of the
buffer multiple times. The mark will be cleared if it is overwritten
during a write.
fn reset(&mut self)
Resets the read position to the previously marked position.
Together with mark
, this can be used to read from a section of the
buffer multiple times.
Panics
This method will panic if no mark has been set,
fn clear(&mut self)
Resets all internal state to the initial state.