[−][src]Trait mem_storage::MemoryStorage
The Memory
trait represents a chunk of memory that can read from,
or written to.
Associated Types
type Error: Debug
The Error
type can be used to indicate if memory access was invalid.
Usually this is just ()
and if Err(())
is returned, it means that the address is out of bounds.
Required methods
fn get<I>(&self, index: I) -> Result<&I::Output, Self::Error> where
I: SliceIndex<[u8]>,
I: SliceIndex<[u8]>,
Returns a reference to an element or subslice depending on the type of index.
fn get_mut<I>(&mut self, index: I) -> Result<&mut I::Output, Self::Error> where
I: SliceIndex<[u8]>,
I: SliceIndex<[u8]>,
Returns a mutable reference to an element or subslice depending on the type of index.
fn try_read_byte(&self, addr: usize) -> Result<u8, Self::Error>
Tries to read a byte at the given address.
Returns Err(x)
if the method failed to read a byte from the address.
fn try_write_byte(&mut self, addr: usize, byte: u8) -> Result<(), Self::Error>
Tries to write a byte to the given address.
Returns Err(x)
if the method failed to write a byte to the address.
Provided methods
fn read_byte(&self, addr: usize) -> u8
Reads a byte at the given address.
Panics if the read failed
fn write_byte(&mut self, addr: usize, byte: u8)
Writes a byte to the given address.
Panics if the write failed
fn try_read<V: Value>(&self, addr: usize) -> Result<V, Self::Error>
Tries to read a generic Value
at the given address using little endian format.
Returns Err(x)
if the method failed to read a value at the address.
fn read<V: Value>(&self, addr: usize) -> V
Reads a generic Value
at the given address using little endian format.
Panics if the method failed to read a value at the address.
fn try_read_be<V: Value>(&self, addr: usize) -> Result<V, Self::Error>
Tries to read a generic Value
at the given address using big endian format.
Returns Err(x)
if the method failed to read a value at the address.
fn read_be<V: Value>(&self, addr: usize) -> V
Reads a generic Value
at the given address using big endian format.
Panics if the method failed to read a value at the address.
fn try_write<V: Value>(
&mut self,
addr: usize,
val: V
) -> Result<(), Self::Error>
&mut self,
addr: usize,
val: V
) -> Result<(), Self::Error>
Tries to write a generic Value
to the given address using little endian format.
Returns Err(x)
if the method failed to write a value to the address.
fn write<V: Value>(&mut self, addr: usize, val: V)
Writes a generic Value
to the given address using little endian format.
Panics if the method failed to write a value to the address.
fn try_write_be<V: Value>(
&mut self,
addr: usize,
val: V
) -> Result<(), Self::Error>
&mut self,
addr: usize,
val: V
) -> Result<(), Self::Error>
Tries to write a generic Value
to the given address using big endian format.
Returns Err(x)
if the method failed to write a value to the address.
fn write_be<V: Value>(&mut self, addr: usize, val: V)
Writes a generic Value
to the given address using big endian format.
Panics if the method failed to write a value to the address.