Struct wasmer::Imports

source ·
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§

source§

impl Imports

source

pub fn new() -> Self

Create a new Imports.

source

pub fn get_export(&self, module: &str, name: &str) -> Option<Extern>

Gets an export given a module and a name

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

pub fn exists(&self, module: &str, name: &str) -> bool

Returns if an export exist for a given module and name.

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

pub fn contains_namespace(&self, name: &str) -> bool

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

source

pub fn register_namespace( &mut self, ns: &str, contents: impl IntoIterator<Item = (String, Extern)>, )

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);
// ...
source

pub fn define(&mut self, ns: &str, name: &str, val: impl Into<Extern>)

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));
source

pub fn get_namespace_exports(&self, name: &str) -> Option<Exports>

Returns the contents of a namespace as an Exports.

Returns None if the namespace doesn’t exist.

source

pub fn imports_for_module( &self, module: &Module, ) -> Result<Vec<Extern>, LinkError>

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.

source

pub fn iter(&self) -> ImportsIterator<'_>

Iterates through all the imports in this structure

Trait Implementations§

source§

impl Clone for Imports

source§

fn clone(&self) -> Imports

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 Debug for Imports

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Imports

source§

fn default() -> Imports

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

impl Extend<((String, String), Extern)> for Imports

source§

fn extend<T: IntoIterator<Item = ((String, String), Extern)>>( &mut self, iter: T, )

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

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl IntoIterator for &Imports

§

type IntoIter = IntoIter<(String, String), Extern>

Which kind of iterator are we turning this into?
§

type Item = ((String, String), Extern)

The type of the elements being iterated over.
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

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> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
source§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<F, W, T, D> Deserialize<With<T, W>, D> for F
where W: DeserializeWith<F, T, D>, D: Fallible + ?Sized, F: ?Sized,

source§

fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>

Deserializes using the given deserializer
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> LayoutRaw for T

source§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Gets the layout of the type.
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

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

impl<T> Pointee for T

§

type Metadata = ()

The type for metadata in pointers and references to Self.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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>,

§

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>,

§

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.
source§

impl<T> Upcastable for T
where T: Any + Send + Sync + 'static,

source§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

upcast ref
source§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

upcast mut ref
source§

fn upcast_any_box(self: Box<T>) -> Box<dyn Any>

upcast boxed dyn
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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