pub trait Buffer {
// Required methods
fn as_slice(&self) -> &[u8] ⓘ;
fn as_mut_slice(&mut self) -> &mut [u8] ⓘ;
fn capacity(&self) -> usize;
fn clear(&mut self);
fn extend_from_slice(&mut self, extend: &[u8]);
// Provided methods
fn len(&self) -> usize { ... }
fn is_empty(&self) -> bool { ... }
fn resize(&mut self, new_len: usize, filler: u8) { ... }
}
Expand description
Operations on a growable in-memory buffer.
This trait is intended to be used as a thin compatibility layer between
Vec<u8>
and
bytes::BytesMut
.
By writing generic code that operates on Buffer
, HotFIX users can
decide for themselves if they want to use bytes
and still use most of the
features.
It’s important to note that, unlike std::io::Write
which only allows
sequential write operations, Buffer
allows arbitrary data manipulation
over the whole buffer.
Required Methods§
Sourcefn as_slice(&self) -> &[u8] ⓘ
fn as_slice(&self) -> &[u8] ⓘ
Returns an immutable reference to the whole contents of the buffer.
Sourcefn as_mut_slice(&mut self) -> &mut [u8] ⓘ
fn as_mut_slice(&mut self) -> &mut [u8] ⓘ
Returns a mutable reference to the whole contents of the buffer.
Sourcefn capacity(&self) -> usize
fn capacity(&self) -> usize
Returns the number of bytes that self
can hold without reallocating.
Sourcefn extend_from_slice(&mut self, extend: &[u8])
fn extend_from_slice(&mut self, extend: &[u8])
Appends the contents of extend
onto self
, growing the buffer if
necessary.
Provided Methods§
Sourcefn resize(&mut self, new_len: usize, filler: u8)
fn resize(&mut self, new_len: usize, filler: u8)
Resizes this Buffer
in-place so that its new len()
is equal to
new_len
.
If new_len
is greater than Buffer::len()
, self
is extended by
the difference, with each additional byte set as filler
. If new_len
is less than Buffer::len()
, self
is simply truncated.