Trait sp_sandbox::SandboxInstance
source · pub trait SandboxInstance<State>: Sized {
type Memory: SandboxMemory;
type EnvironmentBuilder: SandboxEnvironmentBuilder<State, Self::Memory>;
fn new(
code: &[u8],
env_def_builder: &Self::EnvironmentBuilder,
state: &mut State
) -> Result<Self, Error>;
fn invoke(
&mut self,
name: &str,
args: &[Value],
state: &mut State
) -> Result<ReturnValue, Error>;
fn get_global_val(&self, name: &str) -> Option<Value>;
}
Expand description
Sandboxed instance of a wasm module.
This instance can be used for invoking exported functions.
Required Associated Types§
sourcetype Memory: SandboxMemory
type Memory: SandboxMemory
The memory type used for this sandbox.
sourcetype EnvironmentBuilder: SandboxEnvironmentBuilder<State, Self::Memory>
type EnvironmentBuilder: SandboxEnvironmentBuilder<State, Self::Memory>
The environment builder used to construct this sandbox.
Required Methods§
sourcefn new(
code: &[u8],
env_def_builder: &Self::EnvironmentBuilder,
state: &mut State
) -> Result<Self, Error>
fn new(
code: &[u8],
env_def_builder: &Self::EnvironmentBuilder,
state: &mut State
) -> Result<Self, Error>
Instantiate a module with the given EnvironmentDefinitionBuilder
. It will
run the start
function (if it is present in the module) with the given state
.
Returns Err(Error::Module)
if this module can’t be instantiated with the given
environment. If execution of start
function generated a trap, then Err(Error::Execution)
will be returned.
sourcefn invoke(
&mut self,
name: &str,
args: &[Value],
state: &mut State
) -> Result<ReturnValue, Error>
fn invoke(
&mut self,
name: &str,
args: &[Value],
state: &mut State
) -> Result<ReturnValue, Error>
Invoke an exported function with the given name.
Errors
Returns Err(Error::Execution)
if:
- An export function name isn’t a proper utf8 byte sequence,
- This module doesn’t have an exported function with the given name,
- If types of the arguments passed to the function doesn’t match function signature then trap occurs (as if the exported function was called via call_indirect),
- Trap occurred at the execution time.
sourcefn get_global_val(&self, name: &str) -> Option<Value>
fn get_global_val(&self, name: &str) -> Option<Value>
Get the value from a global with the given name
.
Returns Some(_)
if the global could be found.