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§
Sourcetype ReadBuffer: AsRef<[u8]>
type ReadBuffer: AsRef<[u8]>
Bytes read from buffer.
Required Methods§
Sourcefn read_slice(
&self,
ext_memory: &mut E,
position: usize,
slice_len: usize,
) -> Result<Self::ReadBuffer, BufferError<E>>
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.
Sourcefn limit_length(&self, new_len: usize) -> Result<Self, BufferError<E>>
fn limit_length(&self, new_len: usize) -> Result<Self, BufferError<E>>
Restrict the length of the addressable buffer.
Provided Methods§
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.
impl<'a, E: ExternalMemory> AddressableBuffer<E> for &'a [u8]
AddressableBuffer
could be also implemented for regular bytes slices.