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
impl Imports
sourcepub fn get_export(&self, module: &str, name: &str) -> Option<Extern>
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");
sourcepub fn exists(&self, module: &str, name: &str) -> bool
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");
sourcepub fn contains_namespace(&self, name: &str) -> bool
pub fn contains_namespace(&self, name: &str) -> bool
Returns true if the Imports contains namespace with the provided name.
sourcepub fn register_namespace(
&mut self,
ns: &str,
contents: impl IntoIterator<Item = (String, Extern)>,
)
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);
// ...
sourcepub fn define(&mut self, ns: &str, name: &str, val: impl Into<Extern>)
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));
sourcepub fn get_namespace_exports(&self, name: &str) -> Option<Exports>
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.
Trait Implementations§
source§impl Extend<((String, String), Extern)> for Imports
impl Extend<((String, String), Extern)> for Imports
source§fn extend<T: IntoIterator<Item = ((String, String), Extern)>>(
&mut self,
iter: T,
)
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)
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)
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
impl IntoIterator for &Imports
Auto Trait Implementations§
impl Freeze for Imports
impl RefUnwindSafe for Imports
impl Send for Imports
impl Sync for Imports
impl Unpin for Imports
impl UnwindSafe for Imports
Blanket Implementations§
source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moresource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Gets the layout of the type.
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> Upcastable for T
impl<T> Upcastable for T
source§fn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
upcast ref
source§fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
upcast mut ref