Struct Runtime

Source
pub struct Runtime { /* private fields */ }
Expand description

A runtime context for wasm3 modules.

Implementations§

Source§

impl Runtime

Source

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.

Source

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.

Source

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.

Source

pub fn find_function<'rt, ARGS, RET>( &'rt self, name: &str, ) -> Result<Function<'rt, ARGS, RET>>
where ARGS: WasmArgs, RET: WasmType,

Looks up a function by the given name in the loaded modules of this runtime. See Module::find_function for possible error cases.

Source

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.

Source

pub fn modules<'rt>(&'rt self) -> impl Iterator<Item = Module<'rt>> + 'rt

Returns an iterator over the runtime’s loaded modules.

Source

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.

Source

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.

Source

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.

Source

pub fn stack(&self) -> *const [m3slot_t]

Returns the stack of this runtime.

Source

pub fn stack_mut(&self) -> *mut [m3slot_t]

Returns the stack of this runtime.

Trait Implementations§

Source§

impl Debug for Runtime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Runtime

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl !Freeze for Runtime

§

impl !RefUnwindSafe for Runtime

§

impl !Send for Runtime

§

impl !Sync for Runtime

§

impl Unpin for Runtime

§

impl !UnwindSafe for Runtime

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.