Struct buf_redux::Buffer [] [src]

pub struct Buffer { /* 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]

[src]

Create a new buffer with a default capacity.

[src]

Create a new buffer with the given capacity.

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

[src]

Return the number of bytes currently in this buffer.

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

[src]

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.

[src]

Return the total capacity of this buffer.

[src]

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

[src]

Grow the buffer by additional bytes.

Panics

If self.capacity() + additional overflows.

[src]

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

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

[src]

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

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

[src]

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

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

[src]

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

If there is no more room at the head of the buffer, this will return Ok(0).

If <R as TrustRead>::is_trusted(rdr) 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.

[src]

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

This will not grow the buffer if src is larger than self.headroom(); instead, it will fill the headroom and return the number of bytes copied. If there is no headroom, this returns 0.

[src]

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

If the buffer is empty, returns Ok(0).

Panics

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

[src]

Write all bytes in this buffer, ignoring interrupts. Continues writing until the buffer is empty or an error is returned.

Panics

If self.write_to(wrt) panics.

[src]

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

[src]

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

[src]

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

[src]

Empty this buffer by resetting the cursors.

[src]

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

Trait Implementations

impl Debug for Buffer
[src]

[src]

Formats the value using the given formatter.