Struct circular::Buffer [] [src]

pub struct Buffer { /* fields omitted */ }

the Buffer contains the underlying memory and data positions

In all cases, 0 ≤ position ≤ end ≤ capacity should be true

Methods

impl Buffer
[src]

allocates a new buffer of maximum size capacity

allocates a new buffer containing the slice data

the buffer starts full, its available data size is exactly data.len()

increases the size of the buffer

this does nothing if the buffer is already large enough

returns how much data can be read from the buffer

returns how much free space is available to write to

returns the underlying vector's size

returns true if there is no more data to read

advances the position tracker

if the position gets past the buffer's half, this will call shift() to move the remaining data to the beginning of the buffer

after having written data to the buffer, use this function to indicate how many bytes were written

if there is not enough available space, this function can call shift() to move the remaining data to the beginning of the buffer

Get the current position

Examples

use circular::Buffer;
use std::io::{Read,Write};

let mut output = [0;5];

let mut b = Buffer::with_capacity(10);

let res = b.write(&b"abcdefgh"[..]);

b.read(&mut output);

// Position must be 5
assert_eq!(b.position(), 5);
assert_eq!(b.available_data(), 3);

moves the position and end trackers to the beginning this function does not modify the data

returns a slice with all the available data

returns a mutable slice with all the available space to write to

moves the data at the beginning of the buffer

if the position was more than 0, it is now 0

Trait Implementations

impl Debug for Buffer
[src]

Formats the value using the given formatter.

impl PartialEq for Buffer
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Clone for Buffer
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Write for Buffer
[src]

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

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

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

impl Read for Buffer
[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