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]
fn with_capacity(capacity: usize) -> Buffer
allocates a new buffer of maximum size capacity
fn from_slice(data: &[u8]) -> Buffer
allocates a new buffer containing the slice data
the buffer starts full, its available data size is exactly data.len()
fn grow(&mut self, new_size: usize) -> bool
increases the size of the buffer
this does nothing if the buffer is already large enough
fn available_data(&self) -> usize
returns how much data can be read from the buffer
fn available_space(&self) -> usize
returns how much free space is available to write to
fn capacity(&self) -> usize
returns the underlying vector's size
fn empty(&self) -> bool
returns true if there is no more data to read
fn consume(&mut self, count: usize) -> usize
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
fn fill(&mut self, count: usize) -> usize
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
fn position(&self) -> usize
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);
fn reset(&mut self)
moves the position and end trackers to the beginning this function does not modify the data
fn data(&self) -> &[u8]
returns a slice with all the available data
fn space(&mut self) -> &mut [u8]
returns a mutable slice with all the available space to write to
fn shift(&mut self)
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]
impl PartialEq for Buffer
[src]
fn eq(&self, __arg_0: &Buffer) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Buffer) -> bool
This method tests for !=
.
impl Clone for Buffer
[src]
fn clone(&self) -> Buffer
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Write for Buffer
[src]
fn write(&mut self, buf: &[u8]) -> Result<usize>
Write a buffer into this object, returning how many bytes were written. Read more
fn flush(&mut self) -> Result<()>
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0
Attempts to write an entire buffer into this write. 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 Read for Buffer
[src]
fn read(&mut self, buf: &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<usize, Error>
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<usize, Error>
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>
🔬 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 char
s. Read more
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: Read,
1.0.0
R: Read,
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