pub trait WasmInstance: 'static {
// Required methods
fn call(
&mut self,
func: &str,
args: &[WasmVal],
) -> Result<Vec<WasmVal>, WasmError>;
fn memory_read(&self, offset: u32, len: u32) -> Result<Vec<u8>, WasmError>;
fn memory_write(
&mut self,
offset: u32,
data: &[u8],
) -> Result<(), WasmError>;
fn set_fuel(&mut self, fuel: u64) -> Result<(), WasmError>;
fn fuel_consumed(&self) -> Option<u64>;
}Expand description
A fully instantiated WASM module, ready to execute exported functions.
Created by WasmHost::instantiate.
Required Methods§
Sourcefn call(
&mut self,
func: &str,
args: &[WasmVal],
) -> Result<Vec<WasmVal>, WasmError>
fn call( &mut self, func: &str, args: &[WasmVal], ) -> Result<Vec<WasmVal>, WasmError>
Call an exported function by name.
Returns Err(WasmError::FuelExhausted) if the module ran out of fuel,
Err(WasmError::Trap(…)) for other traps, and
Err(WasmError::Call(…)) for missing exports or type errors.
Sourcefn memory_read(&self, offset: u32, len: u32) -> Result<Vec<u8>, WasmError>
fn memory_read(&self, offset: u32, len: u32) -> Result<Vec<u8>, WasmError>
Read len bytes from WASM linear memory at offset.
Returns Err(WasmError::MemoryAccess) on bounds violation.
Sourcefn memory_write(&mut self, offset: u32, data: &[u8]) -> Result<(), WasmError>
fn memory_write(&mut self, offset: u32, data: &[u8]) -> Result<(), WasmError>
Write data into WASM linear memory starting at offset.
Returns Err(WasmError::MemoryAccess) on bounds violation.
Sourcefn set_fuel(&mut self, fuel: u64) -> Result<(), WasmError>
fn set_fuel(&mut self, fuel: u64) -> Result<(), WasmError>
Set the fuel budget for subsequent calls.
Has no effect if the runtime was not configured with fuel consumption
enabled; in that case returns Ok(()) silently.
Sourcefn fuel_consumed(&self) -> Option<u64>
fn fuel_consumed(&self) -> Option<u64>
Return the number of fuel units consumed so far by this instance.
Returns None if the runtime was not configured with fuel tracking.