Struct tokio_core::io::EasyBuf
[−]
[src]
pub struct EasyBuf { /* fields omitted */ }
A reference counted buffer of bytes.
An EasyBuf
is a representation of a byte buffer where sub-slices of it can
be handed out efficiently, each with a 'static
lifetime which keeps the
data alive. The buffer also supports mutation but may require bytes to be
copied to complete the operation.
Methods
impl EasyBuf
[src]
fn new() -> EasyBuf
Creates a new EasyBuf with no data and the default capacity.
fn with_capacity(cap: usize) -> EasyBuf
Creates a new EasyBuf with cap
capacity.
fn len(&self) -> usize
Returns the number of bytes contained in this EasyBuf
.
fn as_slice(&self) -> &[u8]
Returns the inner contents of this EasyBuf
as a slice.
fn split_off(&mut self, at: usize) -> EasyBuf
Splits the buffer into two at the given index.
Afterwards self
contains elements [0, at)
, and the returned EasyBuf
contains elements [at, len)
.
This is an O(1) operation that just increases the reference count and sets a few indexes.
Panics
Panics if at > len
fn drain_to(&mut self, at: usize) -> EasyBuf
Splits the buffer into two at the given index.
Afterwards self
contains elements [at, len)
, and the returned EasyBuf
contains elements [0, at)
.
This is an O(1) operation that just increases the reference count and sets a few indexes.
Panics
Panics if at > len
fn get_mut(&mut self) -> EasyBufMut
Returns a mutable reference to the underlying growable buffer of bytes.
If this EasyBuf
is the only instance pointing at the underlying buffer
of bytes, a direct mutable reference will be returned. Otherwise the
contents of this EasyBuf
will be reallocated in a fresh Vec<u8>
allocation with the same capacity as this allocation, and that
allocation will be returned.
This operation is not O(1) as it may clone the entire contents of this buffer.
The returned EasyBufMut
type implement Deref
and DerefMut
to
Vec<u8>
can the byte buffer can be manipulated using the standard
Vec<u8>
methods.
Trait Implementations
impl Clone for EasyBuf
[src]
fn clone(&self) -> EasyBuf
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