Buffer

Trait Buffer 

Source
pub trait Buffer: Sized + DerefMut<Target = [u8]> {
    // Required methods
    fn new() -> Self;
    fn resize(&mut self, min_length: usize);

    // Provided methods
    fn write_byte(&mut self, pos: usize, byte: u8) { ... }
    fn write(&mut self, pos: usize, bytes: u64, len: usize) { ... }
    fn read_byte(&self, pos: usize) -> u8 { ... }
    fn read(&self, pos: usize, len: usize) -> u64 { ... }
}
Expand description

An auto-growing array of bytes. In addition to the usual slice API, methods are provided for reading or writing up to 8 bytes at a time using a u64.

Vec<u8> implements this trait, which is useful for testing.

Mmap implements this trait and allows the bytes to be executed as code.

Required Methods§

Source

fn new() -> Self

Allocates a fresh Buffer with a default (small) length.

Source

fn resize(&mut self, min_length: usize)

Reallocate this Buffer if necessary to ensure that it holds at least min_length bytes. Panics if the reallocation fails.

Provided Methods§

Source

fn write_byte(&mut self, pos: usize, byte: u8)

Writes a single byte at pos. Writes beyond the end of the buffer resize it to a power-of-two length.

Source

fn write(&mut self, pos: usize, bytes: u64, len: usize)

Writes up to 8 bytes at pos, as if using write_byte() repeatedly, incrementing pos after each call.

Source

fn read_byte(&self, pos: usize) -> u8

Reads a single byte. Reading beyond the end of the buffer gives 0.

Source

fn read(&self, pos: usize, len: usize) -> u64

Reads up to 8 bytes, as if using read_byte() repeatedly.

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 Buffer for Vec<u8>

Source§

fn new() -> Self

Source§

fn resize(&mut self, min_length: usize)

Implementors§