Struct wizer::Wizer[][src]

pub struct Wizer { /* fields omitted */ }

Wizer: the WebAssembly pre-initializer!

Don’t wait for your Wasm module to initialize itself, pre-initialize it! Wizer instantiates your WebAssembly module, executes its initialization function, and then serializes the instance’s initialized state out into a new WebAssembly module. Now you can use this new, pre-initialized WebAssembly module to hit the ground running, without making your users wait for that first-time set up code to complete.

Caveats

  • The initialization function may not call any imported functions. Doing so will trigger a trap and wizer will exit.

  • The Wasm module may not import globals, tables, or memories.

  • Reference types are not supported yet. This is tricky because it would allow the Wasm module to mutate tables, and we would need to be able to snapshot the new table state, but funcrefs and externrefs don’t have identity and aren’t comparable in the Wasm spec, which makes snapshotting difficult.

Implementations

impl Wizer[src]

pub fn new() -> Self[src]

Construct a new Wizer builder.

pub fn init_func(&mut self, init_func: impl Into<String>) -> &mut Self[src]

The export name of the initializer function.

Defaults to "wizer.initialize".

pub fn func_rename(
    &mut self,
    new_name: impl Display,
    old_name: impl Display
) -> &mut Self
[src]

Add a function rename to perform.

pub fn allow_wasi(&mut self, allow: bool) -> &mut Self[src]

Allow WASI imports to be called during initialization?

This can introduce diverging semantics because the initialization can observe nondeterminism that might have gone a different way at runtime than it did at initialization time.

If your Wasm module uses WASI’s get_random to add randomness to something as a security mitigation (e.g. something akin to ASLR or the way Rust’s hash maps incorporate a random nonce) then note that, if the randomization is added during initialization time and you don’t ever re-randomize at runtime, then that randomization will become per-module rather than per-instance.

Defaults to false.

pub fn inherit_stdio(&mut self, inherit: bool) -> &mut Self[src]

When using WASI during initialization, should stdin, stdout, and stderr be inherited?

Defaults to true.

pub fn inherit_env(&mut self, inherit: bool) -> &mut Self[src]

When using WASI during initialization, should the environment variables be inherited?

Defaults to false.

pub fn dir(&mut self, directory: impl Into<PathBuf>) -> &mut Self[src]

When using WASI during initialization, which file system directories should be made available?

None are available by default.

pub fn wasm_multi_memory(&mut self, enable: bool) -> &mut Self[src]

Enable or disable the Wasm multi-memory proposal.

Defaults to true.

pub fn wasm_multi_value(&mut self, enable: bool) -> &mut Self[src]

Enable or disable the Wasm multi-value proposal.

Defaults to true.

pub fn run(&self, wasm: &[u8]) -> Result<Vec<u8>>[src]

Initialize the given Wasm, snapshot it, and return the serialized snapshot as a new, pre-initialized Wasm module.

Trait Implementations

impl Clone for Wizer[src]

impl Debug for Wizer[src]

Auto Trait Implementations

impl RefUnwindSafe for Wizer

impl Send for Wizer

impl Sync for Wizer

impl Unpin for Wizer

impl UnwindSafe for Wizer

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Pointee for T

type Pointer = u32

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,