logo
pub struct Imports { /* private fields */ }
Expand description

All of the import data used when instantiating.

It’s suggested that you use the imports! macro instead of creating an Imports by hand.

Usage:

use wasmer::{Store, Exports, Module, Instance, imports, Imports, Function, FunctionEnvMut};

let host_fn = Function::new_typed(&mut store, foo);
let import_object: Imports = imports! {
    "env" => {
        "foo" => host_fn,
    },
};

let instance = Instance::new(&mut store, &module, &import_object).expect("Could not instantiate module.");

fn foo(n: i32) -> i32 {
    n
}

Implementations

Create a new Imports.

Gets an export given a module and a name

Usage
let mut import_object = Imports::new();
import_object.get_export("module", "name");

Returns true if the Imports contains namespace with the provided name.

Register a list of externs into a namespace.

Usage:
let mut exports = Exports::new();
exports.insert("memory", memory);

let mut import_object = Imports::new();
import_object.register_namespace("env", exports);
// ...

Add a single import with a namespace ns and name name.

Usage
use wasmer::{StoreMut, Imports, Function, FunctionEnvMut};
fn foo(n: i32) -> i32 {
    n
}
let mut import_object = Imports::new();
import_object.define("env", "foo", Function::new_typed(&mut store, foo));

Returns the contents of a namespace as an Exports.

Returns None if the namespace doesn’t exist.

Resolve and return a vector of imports in the order they are defined in the module’s source code.

This means the returned Vec<Extern> might be a subset of the imports contained in self.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Which kind of iterator are we turning this into?

The type of the elements being iterated over.

Creates an iterator from a value. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

The archived version of the pointer metadata for this type.

Converts some archived metadata to the pointer metadata for itself.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Deserializes using the given deserializer

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The type for metadata in pointers and references to Self.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

upcast ref

upcast mut ref

upcast boxed dyn

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more