Struct Linker

Source
pub struct Linker {
    extern_vals: BTreeMap<ImportKey, ExternVal>,
}
Expand description

A linker used to link a module’s imports against extern values previously defined in this Linker context.

§Manual Instantiation vs. Instantiation through Linker

Traditionally, module instances are instantiated via the method Store::module_instantiate, which is part of the official Embedder API defined by the specification. However, this method accepts a list of extern values as an argument. Therefore, if the user wants to manually perform linking they have to figure out the imports of their module, then gather the correct extern values, and finally call the instantiation method.

This process of manual linking is very tedious and error-prone, which is why the Linker exists. It builds on top of the original instantiation method with Linker::module_instantiate. Internally this method performs name resolution and then calls the original instantiation. Name resolution is performed on all extern values which were previously defined in the current context.

§Extern values

An extern value is represented as a ExternVal. It contains an address to some store-allocated instance. In a linker context, every external value is stored in map with a unique key (module name, name). To define new extern value in some linker context, use Linker::define or Linker::define_module_instance.

§Relationship with Store

There is a N-to-1 relationship between the Linker and the Store. This means that multiple linkers can be used with the same store, while every linker may be used only with one specific store.

Due to performance reasons, this bookkeeping is not done by the Linker itself. Instead it is the user’s responsibility to uphold this requirement.

Fields§

§extern_vals: BTreeMap<ImportKey, ExternVal>

All extern values in the current linker context by their import keys.

It is guaranteed that the addresses of all extern values belong to the same Store.

Implementations§

Source§

impl Linker

Source

pub fn new() -> Self

Creates a new Linker that is not yet associated to any specific Store.

Source

pub fn define( &mut self, module_name: String, name: String, extern_val: ExternVal, ) -> Result<(), RuntimeError>

Defines a new extern value in the current Linker context.

§Safety

It must be made sure that this Linker is only used with one specific Store and addresses that belong to that store.

Source

pub fn define_module_instance<T: Config>( &mut self, store: &Store<'_, T>, module_name: String, module: ModuleAddr, ) -> Result<(), RuntimeError>

Defines all exports of some module instance as extern values in the current Linker.

§Safety

It must be guaranteed that this Linker is only ever used with one specific Store and that the given ModuleAddr belongs to this store.

Source

pub fn get(&self, module_name: String, name: String) -> Option<ExternVal>

Tries to get some extern value by its module name and name.

It is guaranteed that the address contained by the returned ExternVal is part of the Store used with this Linker.

Source

pub fn instantiate_pre( &self, validation_info: &ValidationInfo<'_>, ) -> Result<Vec<ExternVal>, RuntimeError>

Performs initial linking of a ValidationInfo’s imports producing a list of extern values usable with Store::module_instantiate.

§A note on type checking

This method does not perform type checking on the extern values. Therefore, using the returned list of extern values may still fail when trying to instantiate a module with it.

§Safety

It must be guaranteed that this Linker is only ever used with one specific Store.

Source

pub fn module_instantiate<'b, T: Config>( &self, store: &mut Store<'b, T>, validation_info: &ValidationInfo<'b>, maybe_fuel: Option<u32>, ) -> Result<InstantiationOutcome, RuntimeError>

Variant of Store::module_instantiate with automatic name resolution in the current Linker context.

§Safety

It must be guaranteed that this Linker is only ever used with one specific Store.

Trait Implementations§

Source§

impl Clone for Linker

Source§

fn clone(&self) -> Linker

Returns a copy 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 Default for Linker

Source§

fn default() -> Linker

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Linker

§

impl RefUnwindSafe for Linker

§

impl Send for Linker

§

impl Sync for Linker

§

impl Unpin for Linker

§

impl UnwindSafe for Linker

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, dst: *mut u8)

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