pub struct Module { /* private fields */ }
Expand description
A parsed and validated WebAssembly module.
Implementations§
source§impl Module
impl Module
sourcepub fn new(engine: &Engine, wasm: &[u8]) -> Result<Self, Error>
pub fn new(engine: &Engine, wasm: &[u8]) -> Result<Self, Error>
Creates a new Wasm Module
from the given Wasm bytecode buffer.
§Note
This parses, validates and translates the buffered Wasm bytecode.
§Errors
- If the Wasm bytecode is malformed or fails to validate.
- If the Wasm bytecode violates restrictions
set in the
Config
used by theengine
. - If Wasmi cannot translate the Wasm bytecode.
sourcepub fn new_streaming(engine: &Engine, stream: impl Read) -> Result<Self, Error>
pub fn new_streaming(engine: &Engine, stream: impl Read) -> Result<Self, Error>
Creates a new Wasm Module
from the given Wasm bytecode stream.
§Note
This parses, validates and translates the Wasm bytecode yielded by stream
.
§Errors
- If the Wasm bytecode is malformed or fails to validate.
- If the Wasm bytecode violates restrictions
set in the
Config
used by theengine
. - If Wasmi cannot translate the Wasm bytecode.
sourcepub unsafe fn new_unchecked(engine: &Engine, wasm: &[u8]) -> Result<Self, Error>
pub unsafe fn new_unchecked(engine: &Engine, wasm: &[u8]) -> Result<Self, Error>
Creates a new Wasm Module
from the given Wasm bytecode buffer.
§Note
This parses and translates the buffered Wasm bytecode.
§Safety
- This does not validate the Wasm bytecode.
- It is the caller’s responsibility that the Wasm bytecode is valid.
- It is the caller’s responsibility that the Wasm bytecode adheres
to the restrictions set by the used
Config
of theengine
. - Violating the above rules is undefined behavior.
§Errors
- If the Wasm bytecode is malformed or contains invalid sections.
- If the Wasm bytecode fails to be compiled by Wasmi.
sourcepub unsafe fn new_streaming_unchecked(
engine: &Engine,
stream: impl Read,
) -> Result<Self, Error>
pub unsafe fn new_streaming_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
.
§Safety
- This does not validate the Wasm bytecode.
- It is the caller’s responsibility that the Wasm bytecode is valid.
- It is the caller’s responsibility that the Wasm bytecode adheres
to the restrictions set by the used
Config
of theengine
. - Violating the above rules is undefined behavior.
§Errors
- If the Wasm bytecode is malformed or contains invalid sections.
- If the Wasm bytecode fails to be compiled by Wasmi.
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>
sourcepub fn custom_sections(&self) -> CustomSectionsIter<'_> ⓘ
pub fn custom_sections(&self) -> CustomSectionsIter<'_> ⓘ
Returns an iterator yielding the custom sections of the Wasm Module
.
§Note
The returned iterator will yield no items if Config::ignore_custom_sections
is set to true
even if the original Wasm module contains custom sections.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Module
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> 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)
clone_to_uninit
)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.