Struct buf_redux::Buffer [] [src]

pub struct Buffer {
    // some fields omitted
}

A deque-like datastructure for managing bytes.

Supports interacting via I/O traits like Read and Write, and direct access.

Methods

impl Buffer
[src]

fn new() -> Self

Create a new buffer with a default capacity.

fn with_capacity(cap: usize) -> Self

Create a new buffer with the given capacity.

If the Vec ends up with extra capacity, Buffer will use all of it.

fn available(&self) -> usize

Return the number of bytes available to be read from this buffer.

Equivalent to self.buf().len().

fn headroom(&self) -> usize

Return the number of bytes that can be read into this buffer before it needs to grow or the data in the buffer needs to be moved.

fn capacity(&self) -> usize

Return the total capacity of this buffer.

fn is_empty(&self) -> bool

Returns true if there are no bytes in the buffer, false otherwise.

fn grow(&mut self, additional: usize)

Grow the buffer by additional bytes.

Panics

If self.capacity() + additional overflows.

fn make_room(&mut self)

Make room in the buffer, moving data down to the beginning if necessary.

Does not grow the buffer or delete unread bytes from it.

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

Get an immutable slice of the available bytes in this buffer.

Call .consume() to remove bytes from the beginning of this slice.

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

Get a mutable slice representing the available bytes in this buffer.

Call .consume() to remove bytes from the beginning of this slice.

fn read_from<R: Read>(&mut self, rdr: &mut R) -> Result<usize>

Read from rdr, returning the number of bytes read or any errors.

If <R as TrustRead>::is_trusted() returns true, this method can avoid zeroing the head of the buffer.

See the TrustRead trait for more information.

Panics

If the returned count from rdr.read() overflows the head cursor of this buffer.

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

Copy from src to the head of this buffer. Returns the number of bytes copied.

Will not grow the buffer if src is larger than self.headroom().

fn write_to<W: Write>(&mut self, wrt: &mut W) -> Result<usize>

Write bytes from this buffer to wrt. Returns the number of bytes written or any errors.

Panics

If the count returned by wrt.write() would overflow the tail cursor if added to it.

fn copy_to_slice(&mut self, out: &mut [u8]) -> usize

Copy bytes to out from this buffer, returning the number of bytes written.

fn push_bytes(&mut self, bytes: &[u8])

Push bytes to the end of the buffer, growing it if necessary.

fn consume(&mut self, amt: usize)

Consume amt bytes from the tail of this buffer. No more than self.available() bytes will be consumed.

fn clear(&mut self)

Empty this buffer by resetting the cursors.

fn into_inner(self) -> Vec<u8>

Move the bytes down the beginning of the buffer and take the inner vector, truncated to the number of bytes available.

Trait Implementations

impl Read for Buffer
[src]

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

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more

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

Read all bytes until EOF in this source, placing them into buf. Read more

fn read_to_string(&mut self, buf: &mut String) -> Result<usizeError>
1.0.0

Read all bytes until EOF in this source, placing them into buf. Read more

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

Read the exact number of bytes required to fill buf. Read more

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

Creates a "by reference" adaptor for this instance of Read. Read more

fn bytes(self) -> Bytes<Self>
1.0.0

Transforms this Read instance to an Iterator over its bytes. Read more

fn chars(self) -> Chars<Self>

Unstable (io)

: the semantics of a partial read/write of where errors happen is currently unclear and may change

Transforms this Read instance to an Iterator over chars. Read more

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

Creates an adaptor which will chain this stream with another. Read more

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

Creates an adaptor which will read at most limit bytes from it. Read more

impl Write for Buffer
[src]

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

Write a buffer into this object, returning how many bytes were written. Read more

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

Attempts to write an entire buffer into this write. Read more

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

Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more

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

Writes a formatted string into this writer, returning any error encountered. Read more

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

Creates a "by reference" adaptor for this instance of Write. Read more

impl Debug for Buffer
[src]

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

Formats the value using the given formatter.