wasmer

Struct 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

Source§

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

Which kind of iterator are we turning this into?
Source§

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

Source§

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§

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

Returns the layout of the type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

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

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
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