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§
fn context(&self) -> &Self::Context
fn context_mut(&mut self) -> &mut Self::Context
Sourcefn has_export(&self, name: &str) -> bool
fn has_export(&self, name: &str) -> bool
Check if an export is present in the module.
fn memory_read_into(&self, offset: u32, output: &mut [u8]) -> VMResult<()>
fn memory_write(&self, offset: u32, data: &[u8]) -> VMResult<()>
Sourcefn alloc(&mut self, idx: u32, size: usize, ctx: u32) -> VMResult<u32>
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.
Sourcefn gas_consumed(&mut self) -> MeteringPoints
fn gas_consumed(&mut self) -> MeteringPoints
Returns the amount of gas used.
Sourcefn consume_gas(&mut self, value: u64) -> VMResult<()>
fn consume_gas(&mut self, value: u64) -> VMResult<()>
Set the amount of gas used.