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
sourceimpl 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 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
sourceimpl Extend<((String, String), Extern)> for Imports
impl Extend<((String, String), Extern)> for Imports
sourcefn 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
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl IntoIterator for &Imports
impl IntoIterator for &Imports
Auto Trait Implementations
impl RefUnwindSafe for Imports
impl Send for Imports
impl Sync for Imports
impl Unpin for Imports
impl UnwindSafe for Imports
Blanket Implementations
impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
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.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for F where
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize(
&self,
deserializer: &mut D
) -> Result<With<T, W>, <D as Fallible>::Error>
Deserializes using the given deserializer
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> Upcastable for T where
T: 'static + Any + Send + Sync,
impl<T> Upcastable for T where
T: 'static + Any + Send + Sync,
sourcefn upcast_any_ref(&self) -> &(dyn Any + 'static)
fn upcast_any_ref(&self) -> &(dyn Any + 'static)
upcast ref
sourcefn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)
upcast mut ref
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more