Trait Write

Source
pub trait Write {
    // Required methods
    fn write(&mut self, buf: &[u8]) -> Result<usize, WriteError>;
    fn write_all(&mut self, buf: &[u8]) -> Result<(), WriteError>;
}
Expand description

Interface for writing data into a buffer.

An abstraction over different buffer types (Vec<u8> or BufferPool), it provides methods for writing data from a byte slice into the buffer, with the option to either write a portion of the data or attempt to write the entire byte slice at once.

Required Methods§

Source

fn write(&mut self, buf: &[u8]) -> Result<usize, WriteError>

Writes data from a byte slice (buf) into the buffer, returning the number of bytes that were successfully written.

Source

fn write_all(&mut self, buf: &[u8]) -> Result<(), WriteError>

Attempts to write the entire byte slice (buf) into the buffer. If the buffer cannot accept the full length of the data, an error is returned.

Implementations on Foreign Types§

Source§

impl Write for &mut [u8]

Source§

fn write(&mut self, data: &[u8]) -> Result<usize, WriteError>

Writes data from a byte slice into a mutable byte array (&mut [u8]), up to the length of the provided buffer.

Source§

fn write_all(&mut self, data: &[u8]) -> Result<(), WriteError>

Attempts to write all the data from a byte slice into a mutable byte array (&mut [u8]). If the buffer is not large enough to contain all the data, an error is returned.

Source§

impl Write for Vec<u8>

Source§

fn write(&mut self, buf: &[u8]) -> Result<usize, WriteError>

Writes data from a byte slice into a Vec<u8> buffer by extending the vector with the contents of the provided slice.

Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), WriteError>

Attempts to write all the data from a byte slice into a Vec<u8> buffer by extending the vector. Since Vec<u8> can dynamically resize, this method will always succeed as long as there is available memory.

Implementors§