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

Method instance

crates/wasmtime/src/runtime/linker.rs:650–673  ·  view source on GitHub ↗

Convenience wrapper to define an entire [`Instance`] in this linker. This function is a convenience wrapper around [`Linker::define`] which will define all exports on `instance` into this linker. The module name for each export is `module_name`, and the name for each export is the name in the instance itself. Note that when this API is used the [`Linker`] is no longer compatible with multi-[`Sto

(
        &mut self,
        mut store: impl AsContextMut<Data = T>,
        module_name: &str,
        instance: Instance,
    )

Source from the content-addressed store, hash-verified

648 /// memory allocation fails. See the `OutOfMemory` type's documentation for
649 /// details on Wasmtime's out-of-memory handling.
650 pub fn instance(
651 &mut self,
652 mut store: impl AsContextMut<Data = T>,
653 module_name: &str,
654 instance: Instance,
655 ) -> Result<&mut Self>
656 where
657 T: 'static,
658 {
659 let mut store = store.as_context_mut();
660 let exports: TryVec<_> = instance
661 .exports(&mut store)
662 .map(|e| {
663 Ok((
664 self.import_key(module_name, Some(e.name()))?,
665 e.into_extern(),
666 ))
667 })
668 .try_collect::<_, Error>()?;
669 for (key, export) in exports {
670 self.insert(key, Definition::new(store.0, export))?;
671 }
672 Ok(self)
673 }
674
675 /// Define automatic instantiations of a [`Module`] in this linker.
676 ///

Callers 2

moduleMethod · 0.45
module_asyncMethod · 0.45

Calls 9

OkFunction · 0.85
import_keyMethod · 0.80
into_externMethod · 0.80
newFunction · 0.50
as_context_mutMethod · 0.45
mapMethod · 0.45
exportsMethod · 0.45
nameMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected