Trait SocketBuffer

Source
pub trait SocketBuffer:
    Clone
    + Debug
    + Default {
    // Required methods
    fn new() -> Self
       where Self: Sized;
    fn append_buffer(&mut self, buf: &[u8]);
    fn shift_left_buffer(&mut self, amount: usize);
    fn as_slice(&self) -> &[u8];
    fn len(&self) -> usize;

    // Provided methods
    fn clear(&mut self) { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

A trait for a buffer that can be used with a socket.

It can be used by either a read or write buffer of a socket.

Required Methods§

Source

fn new() -> Self
where Self: Sized,

Create a new buffer

Source

fn append_buffer(&mut self, buf: &[u8])

Append a buffer to the end.

§Arguments
  • buf: buffer containing the data to be appended
Source

fn shift_left_buffer(&mut self, amount: usize)

Shift the buffer to the left by amount

This is used to remove data from the buffer.

Source

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

Get the buffer as a slice

§Returns
  • The buffer as a slice of bytes
Source

fn len(&self) -> usize

Get the length of the buffer

Provided Methods§

Source

fn clear(&mut self)

Clear the buffer

Source

fn is_empty(&self) -> bool

Check if the buffer is empty

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SocketBuffer for Vec<u8>

Source§

fn new() -> Self

Source§

fn append_buffer(&mut self, buf: &[u8])

Source§

fn shift_left_buffer(&mut self, amount: usize)

Source§

fn len(&self) -> usize

Source§

fn clear(&mut self)

Source§

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

Implementors§