MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / new

Method new

crates/wasmtime/src/runtime/instance.rs:115–129  ·  view source on GitHub ↗

Creates a new [`Instance`] from the previously compiled [`Module`] and list of `imports` specified. This method instantiates the `module` provided with the `imports`, following the procedure in the [core specification][inst] to instantiate. Instantiation can fail for a number of reasons (many specified below), but if successful the `start` function will be automatically run (if specified in the `

(
        mut store: impl AsContextMut,
        module: &Module,
        imports: &[Extern],
    )

Source from the content-addressed store, hash-verified

113 /// memory allocation fails. See the `OutOfMemory` type's documentation for
114 /// details on Wasmtime's out-of-memory handling.
115 pub fn new(
116 mut store: impl AsContextMut,
117 module: &Module,
118 imports: &[Extern],
119 ) -> Result<Instance> {
120 let mut store = store.as_context_mut();
121 store.0.validate_sync_call()?;
122 let imports = Instance::typecheck_externs(store.0, module, imports)?;
123 // Note that the unsafety here should be satisfied by the call to
124 // `typecheck_externs` above which satisfies the condition that all
125 // the imports are valid for this module.
126 vm::assert_ready(unsafe {
127 Instance::new_started(&mut store, module, imports.as_ref(), Asyncness::No)
128 })
129 }
130
131 /// Same as [`Instance::new`], except for usage in [asynchronous stores].
132 ///

Callers

nothing calls this directly

Calls 15

OkFunction · 0.85
validate_sync_callMethod · 0.80
sig_indexMethod · 0.80
assert_readyFunction · 0.70
typecheckFunction · 0.70
emptyFunction · 0.50
as_context_mutMethod · 0.45
as_refMethod · 0.45
reserveMethod · 0.45
definitionMethod · 0.45
tyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected