mod errors;
pub use errors::MemoryAccessError;
pub trait Store: Send {
type ActualStore<'c>: Send;
}
pub trait MemoryReadable<Store: self::Store> {
fn read_byte(&self, store: &mut <Store as self::Store>::ActualStore<'_>, offset: u32) -> u8;
fn read_array<const COUNT: usize>(
&self,
store: &mut <Store as self::Store>::ActualStore<'_>,
offset: u32,
) -> [u8; COUNT];
fn read_vec(
&self,
store: &mut <Store as self::Store>::ActualStore<'_>,
offset: u32,
size: u32,
) -> Vec<u8>;
}
pub trait MemoryWritable<Store: self::Store> {
fn write_byte(
&self,
store: &mut <Store as self::Store>::ActualStore<'_>,
offset: u32,
value: u8,
);
fn write_bytes(
&self,
store: &mut <Store as self::Store>::ActualStore<'_>,
offset: u32,
bytes: &[u8],
);
}
pub trait MemoryView<Store: self::Store>:
Send + MemoryWritable<Store> + MemoryReadable<Store>
{
fn check_bounds(
&self,
store: &mut <Store as self::Store>::ActualStore<'_>,
offset: u32,
size: u32,
) -> Result<(), MemoryAccessError>;
}
pub trait Memory<View, Store: self::Store>: Send
where
View: MemoryView<Store>,
{
fn view(&self) -> View;
}