Struct circbuf::CircBuf [] [src]

pub struct CircBuf { /* fields omitted */ }

Circular Buffer

A growable circular buffer for use with bytes.

Methods

impl CircBuf
[src]

Create a new CircBuf. The default size of the buffer is DEFAULT_CAPACITY bytes.

Create a new CircBuf with a size of cap bytes. The capacity will be rounded up to the nearest power of two greater than or equal to cap. If the nearest power of two overflows usize, return CircBufError::Overflow, else return the buffer.

Get the capacity of the buffer. This value is equal to one less than the length of the underlying buffer because we cannot let the write cursor to ever circle back to being equal with the read cursor.

Get the number of bytes stored in the buffer.

Get the number of bytes available in the buffer.

Get a bool indicating whether the buffer is empty or not.

Get a bool indicating whether the buffer is full or not.

Find the first occurence of val in the buffer starting from index. If val exists in the buffer return the index of the first occurence of val else return None.

Find the first occurence of val in the buffer. If val exists in the buffer return the index of the first occurence of val else return None. A convenience method for find_from_index with 0 as the index.

Get the next byte to be read from the buffer without removing it from it the buffer. Returns the byte if the buffer is not empty, else returns a BufEmpty error.

Get the next byte to be read from the buffer and remove it from it the buffer. Returns the byte if the buffer is not empty, else returns a BufEmpty error.

Put val into the buffer. Returns a BufFull error if the buffer is full, else returns an empty tuple ().

Advance the buffer's read cursor num bytes.

Advance the buffer's write cursor num bytes.

Clear the buffer.

Grow the size of the buffer by factor. The size of the buffer will be rounded up to the nearest power of two that is greater than or equal to the the current size of the buffer multiplied by factor. If the size of the buffer will overflow usize then CircBufError::Overflow will be returned else an empty tuple () will be returned.

Grow the size of the buffer. The buffer will be expanded by a factor of DEFAULT_SIZE_MULTIPLIER. If the size of the buffer will overflow usize then CircBufError::Overflow will be returned else an empty tuple () will be returned.

Return an array that contains two mutable slices which point to the available bytes in the buffer. The combined lengths of the slices will be the minimum of size and self.avail(). If the available bytes in the buffer are contiguous then the second slice will be of size zero. Otherwise, the first slice will point to the bytes available at the end of the buffer and the second slice will point to the bytes available at the start of the buffer. The array can be used for vector IO.

Return an array that contains two slices which point to the bytes that have been written to the buffer. The combined lengths of the slices will be the minimum of size and self.len(). If the bytes are contiguous then the second slice will be of size zero. Otherwise, the first slice will point to the bytes at the end of the buffer and the second slice will point to the bytes available at the start of the buffer.

Return an array that contains two slices which point to the bytes that are available in the buffer. A convenience method for get_avail_upto_size with size equal to self.avail() so all bytes written available in buffer will be returned.

Return an array that contains two slices which point to the bytes that have been written to the buffer. A convenience method for get_bytes_upto_size with size equal to self.len() so all bytes written to the buffer will be returned.

Trait Implementations

impl Debug for CircBuf
[src]

Formats the value using the given formatter.

impl Read for CircBuf
[src]

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

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

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

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

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

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

🔬 This is a nightly-only experimental API. (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

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

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

impl Write for CircBuf
[src]

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

Clear the buffer by setting the read and write pointers to 0.

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

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

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