pub struct Module { /* private fields */ }
Expand description
A parsed and validated WebAssembly module.
Implementations§
source§impl Module
impl Module
sourcepub fn new(engine: &Engine, stream: impl Read) -> Result<Self, Error>
pub fn new(engine: &Engine, stream: impl Read) -> Result<Self, Error>
Creates a new Wasm Module
from the given byte stream.
§Note
This parses, validates and translates the Wasm bytecode yielded by stream
.
§Errors
- If the
stream
cannot be parsed as a valid Wasm module. - If the Wasm bytecode yielded by
stream
is not valid. - If the Wasm bytecode yielded by
stream
violates restrictions set in theConfig
used by theengine
. - If Wasmi cannot translate the Wasm bytecode yielded by
stream
.
sourcepub unsafe fn new_unchecked(
engine: &Engine,
stream: impl Read
) -> Result<Self, Error>
pub unsafe fn new_unchecked( engine: &Engine, stream: impl Read ) -> Result<Self, Error>
Creates a new Wasm Module
from the given byte stream.
§Note
- This parses and translates the Wasm bytecode yielded by
stream
. - This still validates Wasm bytecode outside of function bodies.
§Safety
- This does not fully validate the Wasm bytecode yielded by
stream
. - It is the caller’s responsibility to call this function only with
a
stream
that yields fully valid Wasm bytecode. - Additionally it is the caller’s responsibility that the Wasm bytecode
yielded by
stream
must adhere to the restrictions set by the usedConfig
of theengine
. - Violating these rules may lead to undefined behavior.
§Errors
If the stream
cannot be parsed as a valid Wasm module.
sourcepub fn validate(engine: &Engine, wasm: &[u8]) -> Result<(), Error>
pub fn validate(engine: &Engine, wasm: &[u8]) -> Result<(), Error>
Validates wasm
as a WebAssembly binary given the configuration (via Config
) in engine
.
This function performs Wasm validation of the binary input WebAssembly module and
returns either Ok`` or
Err`` depending on the results of the validation.
The Config
of the engine
is used for Wasm validation which indicates which WebAssembly
features are valid and invalid for the validation.
§Note
- The input
wasm
must be in binary form, the text format is not accepted by this function. - This will only validate the
wasm
but not try to translate it. ThereforeModule::new
might still fail if translation of the Wasm binary input fails to translate via the WasmiEngine
. - Validation automatically happens as part of
Module::new
.
§Errors
If Wasm validation for wasm
fails for the given Config
provided via engine
.
sourcepub fn imports(&self) -> ModuleImportsIter<'_> ⓘ
pub fn imports(&self) -> ModuleImportsIter<'_> ⓘ
Returns an iterator over the imports of the Module
.
sourcepub fn exports(&self) -> ModuleExportsIter<'_> ⓘ
pub fn exports(&self) -> ModuleExportsIter<'_> ⓘ
Returns an iterator over the exports of the Module
.
sourcepub fn get_export(&self, name: &str) -> Option<ExternType>
pub fn get_export(&self, name: &str) -> Option<ExternType>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Module
impl Send for Module
impl Sync for Module
impl Unpin for Module
impl !UnwindSafe for Module
Blanket Implementations§
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
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.