Struct wapc::WapcHost

source ·
pub struct WapcHost { /* private fields */ }
Expand description

A WebAssembly host runtime for waPC-compliant modules

Use an instance of this struct to provide a means of invoking procedure calls by specifying an operation name and a set of bytes representing the opaque operation payload. WapcHost makes no assumptions about the contents or format of either the payload or the operation name, other than that the operation name is a UTF-8 encoded string.

Implementations§

source§

impl WapcHost

source

pub fn new( engine: Box<dyn WebAssemblyEngineProvider>, host_callback: Option<Box<HostCallback>> ) -> Result<Self, Error>

Creates a new instance of a waPC-compliant host runtime paired with a given low-level engine provider

source

pub fn id(&self) -> u64

Returns a reference to the unique identifier of this module. If a parent process has instantiated multiple WapcHosts, then the single static host callback function will contain this value to allow disambiguation of modules

source

pub fn call(&self, op: &str, payload: &[u8]) -> Result<Vec<u8>, Error>

Invokes the __guest_call function within the guest module as per the waPC specification. Provide an operation name and an opaque payload of bytes and the function returns a Result containing either an error or an opaque reply of bytes.

It is worth noting that the first time call is invoked, the WebAssembly module might incur a “cold start” penalty, depending on which underlying engine you’re using. This might be due to lazy initialization or JIT-compilation.

source

pub fn replace_module(&self, module: &[u8]) -> Result<(), Error>

Performs a live “hot swap” of the WebAssembly module. Since all internal waPC execution is assumed to be single-threaded and non-reentrant, this call is synchronous and so you should never attempt to invoke call from another thread while performing this hot swap.

Note: if the underlying engine you’ve chosen is a JITting engine, then performing a swap will re-introduce a “cold start” delay upon the next function call.

If you perform a hot swap of a WASI module, you cannot alter the parameters used to create the WASI module like the environment variables, mapped directories, pre-opened files, etc. Not abiding by this could lead to privilege escalation attacks or non-deterministic behavior after the swap.

Trait Implementations§

source§

impl Debug for WapcHost

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.