pub struct Linker<T> { /* private fields */ }Expand description
A linker used to define module imports and instantiate module instances.
Implementations§
Source§impl<T> Linker<T>
impl<T> Linker<T>
Sourcepub fn build() -> LinkerBuilder<Constructing, T>
pub fn build() -> LinkerBuilder<Constructing, T>
Creates a new LinkerBuilder to construct a Linker.
Sourcepub fn allow_shadowing(&mut self, allow: bool) -> &mut Self
pub fn allow_shadowing(&mut self, allow: bool) -> &mut Self
Configures whether this Linker allows to shadow previous definitions with the same name.
Disabled by default.
Sourcepub fn define(
&mut self,
module: &str,
name: &str,
item: impl Into<Extern>,
) -> Result<&mut Self, LinkerError>
pub fn define( &mut self, module: &str, name: &str, item: impl Into<Extern>, ) -> Result<&mut Self, LinkerError>
Sourcepub fn func_new(
&mut self,
module: &str,
name: &str,
ty: FuncType,
func: impl Fn(Caller<'_, T>, &[Val], &mut [Val]) -> Result<(), Error> + Send + Sync + 'static,
) -> Result<&mut Self, LinkerError>
pub fn func_new( &mut self, module: &str, name: &str, ty: FuncType, func: impl Fn(Caller<'_, T>, &[Val], &mut [Val]) -> Result<(), Error> + Send + Sync + 'static, ) -> Result<&mut Self, LinkerError>
Sourcepub fn func_wrap<Params, Args>(
&mut self,
module: &str,
name: &str,
func: impl IntoFunc<T, Params, Args>,
) -> Result<&mut Self, LinkerError>
pub fn func_wrap<Params, Args>( &mut self, module: &str, name: &str, func: impl IntoFunc<T, Params, Args>, ) -> Result<&mut Self, LinkerError>
Creates a new named Func::new-style host Func for this Linker.
For information how to use this API see Func::wrap.
This method creates a host function for this Linker under the given name.
It is distinct in its ability to create a Store independent
host function. Host functions defined this way can be used to instantiate
instances in multiple different Store entities.
The same applies to other Linker methods to define new Func instances
such as Linker::func_new.
In a concurrently running program, this means that these host functions
could be called concurrently if different Store entities are executing on
different threads.
§Errors
If there already is a definition under the same name for this Linker.
Sourcepub fn get(
&self,
context: impl AsContext<Data = T>,
module: &str,
name: &str,
) -> Option<Extern>
pub fn get( &self, context: impl AsContext<Data = T>, module: &str, name: &str, ) -> Option<Extern>
Sourcepub fn instance(
&mut self,
store: impl AsContextMut<Data = T>,
module_name: &str,
instance: Instance,
) -> Result<&mut Self, Error>
pub fn instance( &mut self, store: impl AsContextMut<Data = T>, module_name: &str, instance: Instance, ) -> Result<&mut Self, Error>
Convenience wrapper to define an entire Instance in this [Linker`].
This is a convenience wrapper around Linker::define which defines all exports of
the instance for self. The module name for each export is module_name and the
field name for each export is the name in the instance itself.
§Errors
- If any item is re-defined in
self(for example the samemodule_namewas already defined). - If
instancecomes from a differentStorethan thisLinkeroriginally was created with.
§Panics
If the Engine of this Linker and the Engine of store are not the same.
Sourcepub fn alias_module(
&mut self,
module: &str,
as_module: &str,
) -> Result<(), Error>
pub fn alias_module( &mut self, module: &str, as_module: &str, ) -> Result<(), Error>
Aliases one module’s name as another.
This method will alias all currently defined under module to also be
defined under the name as_module too.
§Errors
Returns an error if any shadowing violations happen while defining new items.
Sourcepub fn instantiate(
&self,
context: impl AsContextMut<Data = T>,
module: &Module,
) -> Result<InstancePre, Error>
👎Deprecated since 0.49.0: use Linker::instantiate_and_start instead. Prevent start function execution by enabling fuel metering and setting fuel to zero before instantiation.
pub fn instantiate( &self, context: impl AsContextMut<Data = T>, module: &Module, ) -> Result<InstancePre, Error>
Linker::instantiate_and_start instead. Prevent start function execution by enabling fuel metering and setting fuel to zero before instantiation.