pub struct Runtime { /* private fields */ }
Expand description
A runtime context for wasm3 modules.
Implementations§
Source§impl Runtime
impl Runtime
Sourcepub fn new(environment: &Environment, stack_size: u32) -> Result<Self>
pub fn new(environment: &Environment, stack_size: u32) -> Result<Self>
Creates a new runtime with the given stack size in slots.
§Errors
This function will error on memory allocation failure.
Sourcepub fn parse_and_load_module<'rt, TData: Into<Box<[u8]>>>(
&'rt self,
bytes: TData,
) -> Result<Module<'rt>>
pub fn parse_and_load_module<'rt, TData: Into<Box<[u8]>>>( &'rt self, bytes: TData, ) -> Result<Module<'rt>>
Parses and loads a module from bytes.
Sourcepub fn load_module<'rt>(&'rt self, module: ParsedModule) -> Result<Module<'rt>>
pub fn load_module<'rt>(&'rt self, module: ParsedModule) -> Result<Module<'rt>>
Loads a parsed module returning the module if unsuccessful.
§Errors
This function will error if the module’s environment differs from the one this runtime uses.
Sourcepub fn find_function<'rt, ARGS, RET>(
&'rt self,
name: &str,
) -> Result<Function<'rt, ARGS, RET>>
pub fn find_function<'rt, ARGS, RET>( &'rt self, name: &str, ) -> Result<Function<'rt, ARGS, RET>>
Looks up a function by the given name in the loaded modules of this runtime.
See Module::find_function
for possible error cases.
Sourcepub fn find_module<'rt>(&'rt self, name: &str) -> Result<Module<'rt>>
pub fn find_module<'rt>(&'rt self, name: &str) -> Result<Module<'rt>>
Searches for a module with the given name in the runtime’s loaded modules.
Using this over searching through Runtime::modules
is a bit more efficient as it
works on the underlying CStrings directly and doesn’t require an upfront length calculation.
Sourcepub fn modules<'rt>(&'rt self) -> impl Iterator<Item = Module<'rt>> + 'rt
pub fn modules<'rt>(&'rt self) -> impl Iterator<Item = Module<'rt>> + 'rt
Returns an iterator over the runtime’s loaded modules.
Sourcepub fn resize_memory(&self, num_pages: u32) -> Result<()>
pub fn resize_memory(&self, num_pages: u32) -> Result<()>
Resizes the number of allocatable pages to num_pages.
§Errors
This function will error out if it failed to resize memory allocation.
Sourcepub unsafe fn memory(&self) -> *const [u8]
pub unsafe fn memory(&self) -> *const [u8]
Returns the raw memory of this runtime.
§Safety
The returned pointer may get invalidated when wasm function objects are called due to reallocations.
Sourcepub unsafe fn memory_mut(&self) -> *mut [u8]
pub unsafe fn memory_mut(&self) -> *mut [u8]
Returns the raw memory of this runtime.
§Safety
The returned pointer may get invalidated when wasm function objects are called due to reallocations.