Skip to main content

Module

Struct Module 

Source
pub struct Module {
Show 15 fields pub types: Vec<RecGroup>, pub imports: Vec<Import>, pub functions: Vec<Func>, pub tables: Vec<Table>, pub memories: Vec<Memory>, pub tags: Vec<Tag>, pub globals: Vec<Global>, pub exports: Vec<Export>, pub start: Option<u32>, pub elements: Vec<Element>, pub data_count: Option<u32>, pub data: Vec<Data>, pub bodies: Vec<FuncBody>, pub names: NameSection, pub custom_sections: Vec<CustomSection>,
}
Expand description

A decoded WebAssembly module.

Fields§

§types: Vec<RecGroup>

Type section: recursive type groups.

§imports: Vec<Import>

Import section.

§functions: Vec<Func>

Function section: type indices for each function.

§tables: Vec<Table>

Table section.

§memories: Vec<Memory>

Memory section.

§tags: Vec<Tag>

Tag section.

§globals: Vec<Global>

Global section.

§exports: Vec<Export>

Export section.

§start: Option<u32>

Start function index.

§elements: Vec<Element>

Element section.

§data_count: Option<u32>

Data count (from data count section).

§data: Vec<Data>

Data section.

§bodies: Vec<FuncBody>

Function bodies (code section).

§names: NameSection

Parsed name section.

§custom_sections: Vec<CustomSection>

Other custom sections.

Implementations§

Source§

impl Module

Source

pub fn new() -> Self

Create a new empty module.

Source§

impl Module

Source

pub fn find_closest_item(&self, id: &ItemId) -> Option<&dyn Item>

Find the closest enclosing AST item for id.

For most variants this is the item directly identified by the index. For ItemId::Local it returns the enclosing function.

Source

pub fn definitions(&self) -> Vec<(ItemId, Span)>

Return an (ItemId, Span) pair for every definition in the module, in section order. Locals are excluded.

Source§

impl Module

Source

pub fn decode(bytes: &[u8]) -> Result<Module>

Decode a wasm binary into a Module.

Source

pub fn decode_with_options( bytes: &[u8], options: &DecodeOptions, ) -> Result<Module>

Decode a wasm binary with the given options.

Source

pub fn decode_function( &mut self, idx: usize, bytes: &[u8], ) -> Result<&FuncBodyDef>

Decode a single function body, storing the result back into the module. For lazy bodies, bytes must be the original module binary that was passed to decode. Returns a reference to the stored definition.

Source§

impl Module

Source

pub fn encode(&self, bytes: &[u8]) -> Result<Vec<u8>>

Encode this module to a wasm binary. If the module contains lazy function bodies, bytes must be the original module binary that was passed to decode.

Source§

impl Module

Source

pub fn print(&self) -> String

Print the module to WAT text format.

Source

pub fn print_to(&self, p: &mut dyn Printer)

Print the module to WAT text format using a custom printer.

Trait Implementations§

Source§

impl Clone for Module

Source§

fn clone(&self) -> Module

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Module

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Module

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Module

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Module

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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

Source§

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.