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
 
impl Module
Sourcepub fn builder() -> ModuleBuilder
 
pub fn builder() -> ModuleBuilder
Creates a builder for WebAssembly modules.
Sourcepub fn function_types(&self) -> Option<&[FunctionType]>
 
pub fn function_types(&self) -> Option<&[FunctionType]>
The 𝗍𝗒𝗉𝖾𝗌 component of a module defines a vector of function types.
Sourcepub fn functions(&self) -> Option<&[Function]>
 
pub fn functions(&self) -> Option<&[Function]>
The 𝖿𝗎𝗇𝖼𝗌 component of a module defines a vector of functions.
Sourcepub fn tables(&self) -> Option<&[Table]>
 
pub fn tables(&self) -> Option<&[Table]>
The 𝗍𝖺𝖻𝗅𝖾𝗌 component of a module defines a vector of tables described by their table type.
Sourcepub fn memories(&self) -> Option<&[Memory]>
 
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.
Sourcepub fn globals(&self) -> Option<&[Global]>
 
pub fn globals(&self) -> Option<&[Global]>
The 𝗀𝗅𝗈𝖻𝖺𝗅𝗌 component of a module defines a vector of global variables (or globals for short).
Sourcepub fn elements(&self) -> Option<&[Element]>
 
pub fn elements(&self) -> Option<&[Element]>
The 𝖾𝗅𝖾𝗆𝗌 component of a module defines a vector of element segments.
Sourcepub fn data(&self) -> Option<&[Data]>
 
pub fn data(&self) -> Option<&[Data]>
The 𝖽𝖺𝗍𝖺𝗌 component of a module defines a vector of data segments.
Sourcepub fn start(&self) -> Option<&Start>
 
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.
Sourcepub fn imports(&self) -> Option<&[Import]>
 
pub fn imports(&self) -> Option<&[Import]>
The 𝗂𝗆𝗉𝗈𝗋𝗍𝗌 component of a module defines a set of imports that are required for instantiation.
Sourcepub fn exports(&self) -> Option<&[Export]>
 
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.
Sourcepub fn custom_sections_at(
    &self,
    insertion_point: ModuleSection,
) -> Option<&[Custom]>
 
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.
Sourcepub fn data_count(&self) -> Option<u32>
 
pub fn data_count(&self) -> Option<u32>
Whether the module includes the data count section or not.