Module

Struct Module 

Source
pub struct Module { /* private fields */ }
Expand description

WebAssembly programs are organized into modules, which are the unit of deployment, loading, and compilation. A module collects definitions for types, functions, tables, memories, and globals. In addition, it can declare imports and exports and provide initialization in the form of data and element segments, or a start function. Each of the vectors – and thus the entire module – may be empty.

See https://webassembly.github.io/spec/core/syntax/modules.html#modules

§Examples

§Empty

use wasm_ast::{Module, ModuleSection};

let module = Module::empty();

assert_eq!(module.functions(), None);
assert_eq!(module.functions(), None);
assert_eq!(module.tables(), None);
assert_eq!(module.memories(), None);
assert_eq!(module.globals(), None);
assert_eq!(module.elements(), None);
assert_eq!(module.data(), None);
assert_eq!(module.start(), None);
assert_eq!(module.imports(), None);
assert_eq!(module.exports(), None);
assert_eq!(module.data_count(), None);

§Builder

use wasm_ast::{Module, Import, FunctionType, ValueType, Start, Function, ResultType, ControlInstruction, Memory, Limit, Export, Data, Expression, ModuleSection, Custom};

let mut module = Module::builder();
let module = module.build();

assert_eq!(module.functions(), None);
assert_eq!(module.functions(), None);
assert_eq!(module.tables(), None);
assert_eq!(module.memories(), None);
assert_eq!(module.globals(), None);
assert_eq!(module.elements(), None);
assert_eq!(module.data(), None);
assert_eq!(module.start(), None);
assert_eq!(module.imports(), None);
assert_eq!(module.exports(), None);
assert_eq!(module.data_count(), None);

Implementations§

Source§

impl Module

Source

pub fn builder() -> ModuleBuilder

Creates a builder for WebAssembly modules.

Source

pub fn empty() -> Self

Creates a new empty Module.

Source

pub fn function_types(&self) -> Option<&[FunctionType]>

The 𝗍𝗒𝗉𝖾𝗌 component of a module defines a vector of function types.

Source

pub fn functions(&self) -> Option<&[Function]>

The 𝖿𝗎𝗇𝖼𝗌 component of a module defines a vector of functions.

Source

pub fn tables(&self) -> Option<&[Table]>

The 𝗍𝖺𝖻𝗅𝖾𝗌 component of a module defines a vector of tables described by their table type.

Source

pub fn memories(&self) -> Option<&[Memory]>

The 𝗆𝖾𝗆𝗌 component of a module defines a vector of linear memories (or memories for short) as described by their memory type.

Source

pub fn globals(&self) -> Option<&[Global]>

The 𝗀𝗅𝗈𝖻𝖺𝗅𝗌 component of a module defines a vector of global variables (or globals for short).

Source

pub fn elements(&self) -> Option<&[Element]>

The 𝖾𝗅𝖾𝗆𝗌 component of a module defines a vector of element segments.

Source

pub fn data(&self) -> Option<&[Data]>

The 𝖽𝖺𝗍𝖺𝗌 component of a module defines a vector of data segments.

Source

pub fn start(&self) -> Option<&Start>

The 𝗌𝗍𝖺𝗋𝗍 component of a module declares the function index of a start function that is automatically invoked when the module is instantiated, after tables and memories have been initialized.

Source

pub fn imports(&self) -> Option<&[Import]>

The 𝗂𝗆𝗉𝗈𝗋𝗍𝗌 component of a module defines a set of imports that are required for instantiation.

Source

pub fn exports(&self) -> Option<&[Export]>

The 𝖾𝗑𝗉𝗈𝗋𝗍𝗌 component of a module defines a set of exports that become accessible to the host environment once the module has been instantiated.

Source

pub fn custom_sections_at( &self, insertion_point: ModuleSection, ) -> Option<&[Custom]>

The custom sections of a module for a given insertion point. Custom sections are allowed at the beginning of a module and after every other section.

Source

pub fn data_count(&self) -> Option<u32>

Whether the module includes the data count section or not.

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 From<ModuleBuilder> for Module

Source§

fn from(builder: ModuleBuilder) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Module

Source§

fn eq(&self, other: &Module) -> 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 StructuralPartialEq for Module

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