ModuleBuilder

Struct ModuleBuilder 

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

A builder pattern for Modules. The builder performs minimal validation when using the add_* family of methods. The builder validates that the added element would not exceed the maximum size of a u32. No other validations are performed.

Implementations§

Source§

impl ModuleBuilder

Source

pub fn new() -> Self

Creates a new empty builder of WebAssembly modules.

Source

pub fn set_function_types(&mut self, function_types: Option<Vec<FunctionType>>)

Sets the function types segment for the WebAssembly module to be built.

Source

pub fn add_function_type( &mut self, function_type: FunctionType, ) -> Result<TypeIndex, ModelError>

Adds the function type to the module’s segment. Returns the index of the type in the module.

Source

pub fn set_functions(&mut self, functions: Option<Vec<Function>>)

Sets the functions segment for the WebAssembly module to be built.

Source

pub fn add_function( &mut self, function: Function, ) -> Result<FunctionIndex, ModelError>

Adds the function to the module’s segment. Returns the index of the function in the module.

Note: In order for the returned index to be accurate, all function imports must be defined prior to adding any functions.

Source

pub fn set_tables(&mut self, tables: Option<Vec<Table>>)

Sets the table segment for the WebAssembly module to be built.

Source

pub fn add_table(&mut self, table: Table) -> Result<TableIndex, ModelError>

Adds the table to the module’s segment. Returns the index of the table in the module.

Note: In order for the returned index to be accurate, all table imports must be defined prior to adding any tables.

Source

pub fn set_memories(&mut self, memories: Option<Vec<Memory>>)

Sets the tables segment for the WebAssembly module to be built.

Source

pub fn add_memory(&mut self, memory: Memory) -> Result<MemoryIndex, ModelError>

Adds the memory to the module’s segment. Returns the index of the memory in the module.

Note: In order for the returned index to be accurate, all memory imports must be defined prior to adding any memories.

Source

pub fn set_globals(&mut self, globals: Option<Vec<Global>>)

Sets the globals segment for the WebAssembly module to be built.

Source

pub fn add_global(&mut self, global: Global) -> Result<GlobalIndex, ModelError>

Adds the global to the module’s segment. Returns the index of the global in the module.

Note: In order for the returned index to be accurate, all global imports must be defined prior to adding any globals.

Source

pub fn set_elements(&mut self, elements: Option<Vec<Element>>)

Sets the elements segment for the WebAssembly module to be built.

Source

pub fn add_element( &mut self, element: Element, ) -> Result<ElementIndex, ModelError>

Adds the element to the module’s segment. Returns the index of the element in the module.

Source

pub fn set_data(&mut self, data: Option<Vec<Data>>)

Sets the data segment for the WebAssembly module to be built.

Source

pub fn add_data(&mut self, datum: Data) -> Result<DataIndex, ModelError>

Adds the data to the module’s segment. Returns the index of the data in the module.

Source

pub fn set_start(&mut self, start: Option<Start>)

Sets the start segment for the WebAssembly module to be built.

Source

pub fn set_imports(&mut self, imports: Option<Vec<Import>>)

Sets the imports segment for the WebAssembly module to be built.

Source

pub fn add_import(&mut self, import: Import) -> Result<u32, ModelError>

Adds the import to the module’s segment. Returns the index of the import in the module (i.e function, table, memory, or global index).

Source

pub fn set_exports(&mut self, exports: Option<Vec<Export>>)

Sets the exports segment for the WebAssembly module to be built.

Source

pub fn add_export(&mut self, export: Export)

Adds the export to the module’s segment. Returns the index of the export in the module.

Source

pub fn set_custom_sections( &mut self, insertion_point: ModuleSection, custom_sections: Option<Vec<Custom>>, )

Sets the custom section at the given insertion point for the WebAssembly module to be built. WebAssembly binary format allows custom sections to be at the start of a module, or after any other section.

Source

pub fn add_custom_section( &mut self, insertion_point: ModuleSection, custom_section: Custom, )

Adds the export to the module’s segment. Returns the index of the export in the module.

Source

pub fn set_data_count(&mut self, data_count: Option<u32>)

Determines whether the WebAssembly module to be built will include a data count section or not.

Source

pub fn include_data_count(&mut self)

Includes a data count based on the number of data segments currently in this builder.

Source

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

The 𝗍𝗒𝗉𝖾𝗌 component of the module to be built.

Source

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

The 𝖿𝗎𝗇𝖼𝗌 component of the module to be built.

Source

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

The 𝗍𝖺𝖻𝗅𝖾𝗌 component of the module to be built.

Source

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

The 𝗆𝖾𝗆𝗌 component of the module to be built.

Source

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

The 𝗀𝗅𝗈𝖻𝖺𝗅𝗌 component of the module to be built.

Source

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

The 𝖾𝗅𝖾𝗆𝗌 component of the module to be built.

Source

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

The 𝖽𝖺𝗍𝖺𝗌 component of the module to be built.

Source

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

The 𝗌𝗍𝖺𝗋𝗍 component of the module to be built.

Source

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

The 𝗂𝗆𝗉𝗈𝗋𝗍𝗌 component of the module to be built.

Source

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

The 𝖾𝗑𝗉𝗈𝗋𝗍𝗌 component of the module to be built.

Source

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

The custom sections of the module to be built.

Source

pub fn build(self) -> Module

Builds the current segments into a module.

Trait Implementations§

Source§

impl Default for ModuleBuilder

Source§

fn default() -> Self

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

impl From<ModuleBuilder> for Module

Source§

fn from(builder: ModuleBuilder) -> Self

Converts to this type from the input type.

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

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.