Buffer

Trait Buffer 

Source
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§

Source

fn as_slice(&self) -> &[u8]

Returns an immutable reference to the whole contents of the buffer.

Source

fn as_mut_slice(&mut self) -> &mut [u8]

Returns a mutable reference to the whole contents of the buffer.

Source

fn capacity(&self) -> usize

Returns the number of bytes that self can hold without reallocating.

Source

fn clear(&mut self)

Completely erases the contents of self.

Source

fn extend_from_slice(&mut self, extend: &[u8])

Appends the contents of extend onto self, growing the buffer if necessary.

Provided Methods§

Source

fn len(&self) -> usize

Returns the length of the whole contents of the buffer.

Source

fn is_empty(&self) -> bool

Returns true if the buffer is empty.

Source

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.

Implementations on Foreign Types§

Source§

impl Buffer for Vec<u8>

Source§

fn as_slice(&self) -> &[u8]

Source§

fn as_mut_slice(&mut self) -> &mut [u8]

Source§

fn capacity(&self) -> usize

Source§

fn clear(&mut self)

Source§

fn extend_from_slice(&mut self, extend: &[u8])

Source§

fn resize(&mut self, new_len: usize, filler: u8)

Implementors§