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 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.
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
§impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere
W: DeserializeWith<F, T, D>,
D: Fallible + ?Sized,
F: ?Sized,
impl<F, W, T, D> Deserialize<With<T, W>, D> for Fwhere 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
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>
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§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.