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