Trait MemoryStorage

Source
pub trait MemoryStorage {
    type Error: Debug;

Show 14 methods // Required methods 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>; // Provided methods 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) { ... }
}
Expand description

The Memory trait represents a chunk of memory that can read from, or written to.

Required Associated Types§

Source

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§

Source

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.

Source

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.

Source

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.

Source

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§

Source

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

Reads a byte at the given address.

Panics if the read failed

Source

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

Writes a byte to the given address.

Panics if the write failed

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

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.

Implementors§