Trait AddressableBuffer

Source
pub trait AddressableBuffer<E: ExternalMemory>: Sized {
    type ReadBuffer: AsRef<[u8]>;

    // Required methods
    fn total_len(&self) -> usize;
    fn read_slice(
        &self,
        ext_memory: &mut E,
        position: usize,
        slice_len: usize,
    ) -> Result<Self::ReadBuffer, BufferError<E>>;
    fn limit_length(&self, new_len: usize) -> Result<Self, BufferError<E>>;

    // Provided method
    fn read_byte(
        &self,
        ext_memory: &mut E,
        position: usize,
    ) -> Result<u8, BufferError<E>> { ... }
}
Expand description

Bytes access through ExternalMemory.

Could be implemented, for example, for a combination of an address in external memory and corresponding bytes slice length.

Required Associated Types§

Source

type ReadBuffer: AsRef<[u8]>

Bytes read from buffer.

Required Methods§

Source

fn total_len(&self) -> usize

Total length of the addressable buffer.

Source

fn read_slice( &self, ext_memory: &mut E, position: usize, slice_len: usize, ) -> Result<Self::ReadBuffer, BufferError<E>>

Read bytes slice of known length at known relative position.

Important to keep read_slice, not read_byte as a basic reader tool, because of commonly occuring pages in memory.

Source

fn limit_length(&self, new_len: usize) -> Result<Self, BufferError<E>>

Restrict the length of the addressable buffer.

Provided Methods§

Source

fn read_byte( &self, ext_memory: &mut E, position: usize, ) -> Result<u8, BufferError<E>>

Read single byte at known position.

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<'a, E: ExternalMemory> AddressableBuffer<E> for &'a [u8]

AddressableBuffer could be also implemented for regular bytes slices.

Source§

type ReadBuffer = &'a [u8]

Source§

fn total_len(&self) -> usize

Source§

fn read_slice( &self, _ext_memory: &mut E, position: usize, slice_len: usize, ) -> Result<Self::ReadBuffer, BufferError<E>>

Source§

fn limit_length(&self, new_len: usize) -> Result<Self, BufferError<E>>

Implementors§