Struct wasmi::Module

source ·
pub struct Module { /* private fields */ }
Expand description

A parsed and validated WebAssembly module.

Implementations§

source§

impl Module

source

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 the engine.
  • If Wasmi cannot translate the Wasm bytecode.
source

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 the engine.
  • If Wasmi cannot translate the Wasm bytecode.
source

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 the engine.
  • 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.
source

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 the engine.
  • 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.
source

pub fn engine(&self) -> &Engine

Returns the Engine used during creation of the Module.

source

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. Therefore Module::new might still fail if translation of the Wasm binary input fails to translate via the Wasmi Engine.
  • Validation automatically happens as part of Module::new.
§Errors

If Wasm validation for wasm fails for the given Config provided via engine.

source

pub fn imports(&self) -> ModuleImportsIter<'_>

Returns an iterator over the imports of the Module.

source

pub fn exports(&self) -> ModuleExportsIter<'_>

Returns an iterator over the exports of the Module.

source

pub fn get_export(&self, name: &str) -> Option<ExternType>

Looks up an export in this Module by its name.

Returns None if no export with the name was found.

§Note

This function will return the type of an export with the given name.

Trait Implementations§

source§

impl Debug for Module

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.