Trait object::write::WritableBuffer

source ·
pub trait WritableBuffer {
    // Required methods
    fn len(&self) -> usize;
    fn reserve(&mut self, size: usize) -> Result<(), ()>;
    fn resize(&mut self, new_len: usize);
    fn write_bytes(&mut self, val: &[u8]);

    // Provided methods
    fn write_pod<T: Pod>(&mut self, val: &T)
       where Self: Sized { ... }
    fn write_pod_slice<T: Pod>(&mut self, val: &[T])
       where Self: Sized { ... }
}
Expand description

Trait for writable buffer.

Required Methods§

source

fn len(&self) -> usize

Returns position/offset for data to be written at.

Should only be used in debug assertions

source

fn reserve(&mut self, size: usize) -> Result<(), ()>

Reserves specified number of bytes in the buffer.

This will be called exactly once before writing anything to the buffer, and the given size is the exact total number of bytes that will be written.

source

fn resize(&mut self, new_len: usize)

Writes zero bytes at the end of the buffer until the buffer has the specified length.

source

fn write_bytes(&mut self, val: &[u8])

Writes the specified slice of bytes at the end of the buffer.

Provided Methods§

source

fn write_pod<T: Pod>(&mut self, val: &T)
where Self: Sized,

Writes the specified Pod type at the end of the buffer.

source

fn write_pod_slice<T: Pod>(&mut self, val: &[T])
where Self: Sized,

Writes the specified Pod slice at the end of the buffer.

Implementations§

source§

impl<'a> dyn WritableBuffer + 'a

source

pub fn write<T: Pod>(&mut self, val: &T)

Writes the specified Pod type at the end of the buffer.

source

pub fn write_slice<T: Pod>(&mut self, val: &[T])

Writes the specified Pod slice at the end of the buffer.

Implementations on Foreign Types§

source§

impl WritableBuffer for Vec<u8>

source§

fn len(&self) -> usize

source§

fn reserve(&mut self, size: usize) -> Result<(), ()>

source§

fn resize(&mut self, new_len: usize)

source§

fn write_bytes(&mut self, val: &[u8])

Implementors§