[][src]Trait mem_storage::MemoryStorage

pub trait MemoryStorage {
    type Error: Debug;
    fn get<I>(&self, index: I) -> Result<&I::Output, Self::Error>
    where
        I: SliceIndex<[u8]>
;
fn get_mut<I>(&mut self, index: I) -> Result<&mut I::Output, Self::Error>
    where
        I: SliceIndex<[u8]>
;
fn try_read_byte(&self, addr: usize) -> Result<u8, Self::Error>;
fn try_write_byte(
        &mut self,
        addr: usize,
        byte: u8
    ) -> Result<(), Self::Error>; fn read_byte(&self, addr: usize) -> u8 { ... }
fn write_byte(&mut self, addr: usize, byte: u8) { ... }
fn try_read<V: Value>(&self, addr: usize) -> Result<V, Self::Error> { ... }
fn read<V: Value>(&self, addr: usize) -> V { ... }
fn try_read_be<V: Value>(&self, addr: usize) -> Result<V, Self::Error> { ... }
fn read_be<V: Value>(&self, addr: usize) -> V { ... }
fn try_write<V: Value>(
        &mut self,
        addr: usize,
        val: V
    ) -> Result<(), Self::Error> { ... }
fn write<V: Value>(&mut self, addr: usize, val: V) { ... }
fn try_write_be<V: Value>(
        &mut self,
        addr: usize,
        val: V
    ) -> Result<(), Self::Error> { ... }
fn write_be<V: Value>(&mut self, addr: usize, val: V) { ... } }

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.

Loading content...

Required methods

fn get<I>(&self, index: I) -> Result<&I::Output, Self::Error> where
    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]>, 

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.

Loading content...

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>

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>

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.

Loading content...

Implementors

Loading content...