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,

Trait Implementations

impl Clone for RingBuf

fn clone(&self) -> RingBuf

fn clone_from(&mut self, source: &Self)

impl Debug for RingBuf

fn fmt(&self, fmt: &mut Formatter) -> Result

impl Buf for RingBuf

fn remaining(&self) -> usize

fn bytes(&self) -> &[u8]

fn advance(&mut self, cnt: usize)

fn has_remaining(&self) -> bool

fn read_slice(&mut self, dst: &mut [u8]) -> usize

fn read_byte(&mut self) -> Option<u8>

impl MutBuf for RingBuf

fn remaining(&self) -> usize

fn advance(&mut self, cnt: usize)

fn mut_bytes(&mut self) -> &mut [u8]

fn has_remaining(&self) -> bool

fn write_slice(&mut self, src: &[u8]) -> usize

fn write_byte(&mut self, byte: u8) -> bool

impl Read for RingBuf

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

fn by_ref(&mut self) -> &mut Self

fn bytes(self) -> Bytes<Self>

fn chars(self) -> Chars<Self>

fn chain<R>(self, next: R) -> Chain<Self, R> where R: Read

fn take(self, limit: u64) -> Take<Self>

fn tee<W>(self, out: W) -> Tee<Self, W> where W: Write

impl Write for RingBuf

fn write(&mut self, buf: &[u8]) -> Result<usize>

fn flush(&mut self) -> Result<()>

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

fn write_fmt(&mut self, fmt: Arguments) -> Result<(), Error>

fn by_ref(&mut self) -> &mut Self

fn broadcast<W>(self, other: W) -> Broadcast<Self, W> where W: Write

impl Send for RingBuf