Trait Caller

Source
pub trait Caller {
    type Context;

    // Required methods
    fn context(&self) -> &Self::Context;
    fn context_mut(&mut self) -> &mut Self::Context;
    fn bytecode(&self) -> Bytes;
    fn has_export(&self, name: &str) -> bool;
    fn memory_read_into(&self, offset: u32, output: &mut [u8]) -> VMResult<()>;
    fn memory_write(&self, offset: u32, data: &[u8]) -> VMResult<()>;
    fn alloc(&mut self, idx: u32, size: usize, ctx: u32) -> VMResult<u32>;
    fn gas_consumed(&mut self) -> MeteringPoints;
    fn consume_gas(&mut self, value: u64) -> VMResult<()>;

    // Provided method
    fn memory_read(&self, offset: u32, size: usize) -> VMResult<Vec<u8>> { ... }
}
Expand description

An abstraction over the ‘caller’ object of a host function that works for any Wasm VM.

This allows access for important instances such as the context object that was passed to the instance, wasm linear memory access, etc.

Required Associated Types§

Required Methods§

Source

fn context(&self) -> &Self::Context

Source

fn context_mut(&mut self) -> &mut Self::Context

Source

fn bytecode(&self) -> Bytes

Returns currently running unmodified bytecode.

Source

fn has_export(&self, name: &str) -> bool

Check if an export is present in the module.

Source

fn memory_read_into(&self, offset: u32, output: &mut [u8]) -> VMResult<()>

Source

fn memory_write(&self, offset: u32, data: &[u8]) -> VMResult<()>

Source

fn alloc(&mut self, idx: u32, size: usize, ctx: u32) -> VMResult<u32>

Allocates memory inside the Wasm VM by calling an export.

Error is a type-erased error coming from the VM itself.

Source

fn gas_consumed(&mut self) -> MeteringPoints

Returns the amount of gas used.

Source

fn consume_gas(&mut self, value: u64) -> VMResult<()>

Set the amount of gas used.

Provided Methods§

Source

fn memory_read(&self, offset: u32, size: usize) -> VMResult<Vec<u8>>

Implementors§