Wizer

Struct Wizer 

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

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§

Source§

impl Wizer

Source

pub async fn run<T: Send>( &self, store: &mut Store<T>, wasm: &[u8], instantiate: impl AsyncFnOnce(&mut Store<T>, &Module) -> Result<Instance>, ) -> Result<Vec<u8>>

Available on crate feature wasmtime only.

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

Source§

impl Wizer

Source

pub async fn run_component<T: Send>( &self, store: &mut Store<T>, wasm: &[u8], instantiate: impl AsyncFnOnce(&mut Store<T>, &Component) -> Result<Instance>, ) -> Result<Vec<u8>>

Available on crate features component-model and wasmtime only.

Same as Wizer::run, except for components.

Source§

impl Wizer

Source

pub fn instrument_component<'a>( &self, wasm: &'a [u8], ) -> Result<(ComponentContext<'a>, Vec<u8>)>

Available on crate feature component-model only.

Same as Wizer::instrument, except for components.

Source

pub async fn snapshot_component( &self, cx: ComponentContext<'_>, instance: &mut impl ComponentInstanceState, ) -> Result<Vec<u8>>

Available on crate feature component-model only.

Same as Wizer::snapshot, except for components.

Source§

impl Wizer

Source

pub fn new() -> Self

Construct a new Wizer builder.

Source

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

The export name of the initializer function.

Defaults to "wizer-initialize".

Source

pub fn get_init_func(&self) -> &str

Returns the initialization function that will be run for wizer.

Source

pub fn func_rename(&mut self, new_name: &str, old_name: &str) -> &mut Self

Add a function rename to perform.

Source

pub fn keep_init_func(&mut self, keep: bool) -> &mut Self

After initialization, should the Wasm module still export the initialization function?

This is false by default, meaning that the initialization function is no longer exported from the Wasm module.

Source

pub fn instrument<'a>( &self, wasm: &'a [u8], ) -> Result<(ModuleContext<'a>, Vec<u8>)>

First half of Self::run which instruments the provided wasm and produces a new wasm module which should be run by a runtime.

After the returned wasm is executed the context returned here and the state of the instance should be passed to Self::snapshot.

Source

pub async fn snapshot( &self, cx: ModuleContext<'_>, instance: &mut impl InstanceState, ) -> Result<Vec<u8>>

Second half of Self::run which takes the ModuleContext returned by Self::instrument and the state of the instance after it has possibly executed its initialization function.

This returns a new WebAssembly binary which has all state pre-initialized.

Trait Implementations§

Source§

impl Args for Wizer

Source§

fn group_id() -> Option<Id>

Report the ArgGroup::id for this set of arguments
Source§

fn augment_args<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate Self via FromArgMatches::from_arg_matches_mut Read more
Source§

fn augment_args_for_update<'b>(__clap_app: Command) -> Command

Append to Command so it can instantiate self via FromArgMatches::update_from_arg_matches_mut Read more
Source§

impl Clone for Wizer

Source§

fn clone(&self) -> Wizer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CommandFactory for Wizer

Source§

fn command<'b>() -> Command

Build a Command that can instantiate Self. Read more
Source§

fn command_for_update<'b>() -> Command

Build a Command that can update self. Read more
Source§

impl Debug for Wizer

Source§

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

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

impl FromArgMatches for Wizer

Source§

fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>

Instantiate Self from ArgMatches, parsing the arguments as needed. Read more
Source§

fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>

Assign values from ArgMatches to self.
Source§

impl Parser for Wizer

Source§

fn parse() -> Self

Parse from std::env::args_os(), exit on error.
Source§

fn try_parse() -> Result<Self, Error>

Parse from std::env::args_os(), return Err on error.
Source§

fn parse_from<I, T>(itr: I) -> Self
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, exit on error.
Source§

fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Parse from iterator, return Err on error.
Source§

fn update_from<I, T>(&mut self, itr: I)
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, exit on error. Read more
Source§

fn try_update_from<I, T>(&mut self, itr: I) -> Result<(), Error>
where I: IntoIterator<Item = T>, T: Into<OsString> + Clone,

Update from iterator, return Err on error.

Auto Trait Implementations§

§

impl Freeze for Wizer

§

impl RefUnwindSafe for Wizer

§

impl Send for Wizer

§

impl Sync for Wizer

§

impl Unpin for Wizer

§

impl UnwindSafe for Wizer

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.