MemoryAccessManager

Struct MemoryAccessManager 

Source
pub struct MemoryAccessManager<Ext> { /* private fields */ }
Expand description

Memory access manager. Allows to pre-register memory accesses, and pre-process, them together. For example:

let manager = MemoryAccessManager::default();
let read1 = manager.new_read(10, 20);
let read2 = manager.new_read_as::<u128>(100);
let write1 = manager.new_write_as::<usize>(190);

// First call of read or write interface leads to pre-processing of
// all already registered memory accesses, and clear `self.reads` and `self.writes`.
let value_u128 = manager.read_as(read2).unwrap();

// Next calls do not lead to access pre-processing.
let value1 = manager.read().unwrap();
manager.write_as(write1, 111).unwrap();

Implementations§

Source§

impl<Ext: BackendExternalities> MemoryAccessManager<Ext>

Source

pub fn read<M: Memory>( &mut self, memory: &M, read: WasmMemoryRead, gas_counter: &mut u64, ) -> Result<Vec<u8>, MemoryAccessError>

Pre-process registered accesses if need and read data from memory into new vector.

Source

pub fn read_decoded<M: Memory, T: Decode + MaxEncodedLen>( &mut self, memory: &M, read: WasmMemoryReadDecoded<T>, gas_counter: &mut u64, ) -> Result<T, MemoryAccessError>

Pre-process registered accesses if need and read and decode data as T from memory.

Source

pub fn read_as<M: Memory, T: Sized>( &mut self, memory: &M, read: WasmMemoryReadAs<T>, gas_counter: &mut u64, ) -> Result<T, MemoryAccessError>

Pre-process registered accesses if need and read data as T from memory.

Source

pub fn write<M: Memory>( &mut self, memory: &mut M, write: WasmMemoryWrite, buff: &[u8], gas_counter: &mut u64, ) -> Result<(), MemoryAccessError>

Pre-process registered accesses if need and write data from buff to memory.

Source

pub fn write_as<M: Memory, T: Sized>( &mut self, memory: &mut M, write: WasmMemoryWriteAs<T>, obj: T, gas_counter: &mut u64, ) -> Result<(), MemoryAccessError>

Pre-process registered accesses if need and write obj data to memory.

Trait Implementations§

Source§

impl<Ext: Debug> Debug for MemoryAccessManager<Ext>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Ext> Default for MemoryAccessManager<Ext>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<Ext> MemoryAccessRecorder for MemoryAccessManager<Ext>

Source§

fn register_read(&mut self, ptr: u32, size: u32) -> WasmMemoryRead

Register new read access.
Source§

fn register_read_as<T: Sized>(&mut self, ptr: u32) -> WasmMemoryReadAs<T>

Register new read static size type access.
Source§

fn register_read_decoded<T: Decode + MaxEncodedLen>( &mut self, ptr: u32, ) -> WasmMemoryReadDecoded<T>

Register new read decoded type access.
Source§

fn register_write(&mut self, ptr: u32, size: u32) -> WasmMemoryWrite

Register new write access.
Source§

fn register_write_as<T: Sized>(&mut self, ptr: u32) -> WasmMemoryWriteAs<T>

Register new write static size access.

Auto Trait Implementations§

§

impl<Ext> Freeze for MemoryAccessManager<Ext>

§

impl<Ext> RefUnwindSafe for MemoryAccessManager<Ext>
where Ext: RefUnwindSafe,

§

impl<Ext> Send for MemoryAccessManager<Ext>
where Ext: Send,

§

impl<Ext> Sync for MemoryAccessManager<Ext>
where Ext: Sync,

§

impl<Ext> Unpin for MemoryAccessManager<Ext>
where Ext: Unpin,

§

impl<Ext> UnwindSafe for MemoryAccessManager<Ext>
where Ext: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> JsonSchemaMaybe for T