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
wizerwill 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
impl Wizer
Sourcepub 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.
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>>
wasmtime only.Initialize the given Wasm, snapshot it, and return the serialized snapshot as a new, pre-initialized Wasm module.
Source§impl Wizer
impl Wizer
Sourcepub 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.
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>>
component-model and wasmtime only.Same as Wizer::run, except for components.
Source§impl Wizer
impl Wizer
Sourcepub fn instrument_component<'a>(
&self,
wasm: &'a [u8],
) -> Result<(ComponentContext<'a>, Vec<u8>)>
Available on crate feature component-model only.
pub fn instrument_component<'a>( &self, wasm: &'a [u8], ) -> Result<(ComponentContext<'a>, Vec<u8>)>
component-model only.Same as Wizer::instrument, except for components.
Sourcepub async fn snapshot_component(
&self,
cx: ComponentContext<'_>,
instance: &mut impl ComponentInstanceState,
) -> Result<Vec<u8>>
Available on crate feature component-model only.
pub async fn snapshot_component( &self, cx: ComponentContext<'_>, instance: &mut impl ComponentInstanceState, ) -> Result<Vec<u8>>
component-model only.Same as Wizer::snapshot, except for components.
Source§impl Wizer
impl Wizer
Sourcepub fn init_func(&mut self, init_func: impl Into<String>) -> &mut Self
pub fn init_func(&mut self, init_func: impl Into<String>) -> &mut Self
The export name of the initializer function.
Defaults to "wizer-initialize".
Sourcepub fn get_init_func(&self) -> &str
pub fn get_init_func(&self) -> &str
Returns the initialization function that will be run for wizer.
Sourcepub fn func_rename(&mut self, new_name: &str, old_name: &str) -> &mut Self
pub fn func_rename(&mut self, new_name: &str, old_name: &str) -> &mut Self
Add a function rename to perform.
Sourcepub fn keep_init_func(&mut self, keep: bool) -> &mut Self
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.
Sourcepub fn instrument<'a>(
&self,
wasm: &'a [u8],
) -> Result<(ModuleContext<'a>, Vec<u8>)>
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.
Sourcepub async fn snapshot(
&self,
cx: ModuleContext<'_>,
instance: &mut impl InstanceState,
) -> Result<Vec<u8>>
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
impl Args for Wizer
Source§fn augment_args<'b>(__clap_app: Command) -> Command
fn augment_args<'b>(__clap_app: Command) -> Command
Source§fn augment_args_for_update<'b>(__clap_app: Command) -> Command
fn augment_args_for_update<'b>(__clap_app: Command) -> Command
Command so it can instantiate self via
FromArgMatches::update_from_arg_matches_mut Read moreSource§impl CommandFactory for Wizer
impl CommandFactory for Wizer
Source§impl FromArgMatches for Wizer
impl FromArgMatches for Wizer
Source§fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
fn from_arg_matches(__clap_arg_matches: &ArgMatches) -> Result<Self, Error>
Source§fn from_arg_matches_mut(
__clap_arg_matches: &mut ArgMatches,
) -> Result<Self, Error>
fn from_arg_matches_mut( __clap_arg_matches: &mut ArgMatches, ) -> Result<Self, Error>
Source§fn update_from_arg_matches(
&mut self,
__clap_arg_matches: &ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches( &mut self, __clap_arg_matches: &ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§fn update_from_arg_matches_mut(
&mut self,
__clap_arg_matches: &mut ArgMatches,
) -> Result<(), Error>
fn update_from_arg_matches_mut( &mut self, __clap_arg_matches: &mut ArgMatches, ) -> Result<(), Error>
ArgMatches to self.Source§impl Parser for Wizer
impl Parser for Wizer
Source§fn parse_from<I, T>(itr: I) -> Self
fn parse_from<I, T>(itr: I) -> Self
Source§fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
fn try_parse_from<I, T>(itr: I) -> Result<Self, Error>
Source§fn update_from<I, T>(&mut self, itr: I)
fn update_from<I, T>(&mut self, itr: I)
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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