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
impl ModuleBuilder
Sourcepub fn set_function_types(&mut self, function_types: Option<Vec<FunctionType>>)
pub fn set_function_types(&mut self, function_types: Option<Vec<FunctionType>>)
Sets the function types segment for the WebAssembly module to be built.
Sourcepub fn add_function_type(
&mut self,
function_type: FunctionType,
) -> Result<TypeIndex, ModelError>
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.
Sourcepub fn set_functions(&mut self, functions: Option<Vec<Function>>)
pub fn set_functions(&mut self, functions: Option<Vec<Function>>)
Sets the functions segment for the WebAssembly module to be built.
Sourcepub fn add_function(
&mut self,
function: Function,
) -> Result<FunctionIndex, ModelError>
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.
Sourcepub fn set_tables(&mut self, tables: Option<Vec<Table>>)
pub fn set_tables(&mut self, tables: Option<Vec<Table>>)
Sets the table segment for the WebAssembly module to be built.
Sourcepub fn add_table(&mut self, table: Table) -> Result<TableIndex, ModelError>
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.
Sourcepub fn set_memories(&mut self, memories: Option<Vec<Memory>>)
pub fn set_memories(&mut self, memories: Option<Vec<Memory>>)
Sets the tables segment for the WebAssembly module to be built.
Sourcepub fn add_memory(&mut self, memory: Memory) -> Result<MemoryIndex, ModelError>
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.
Sourcepub fn set_globals(&mut self, globals: Option<Vec<Global>>)
pub fn set_globals(&mut self, globals: Option<Vec<Global>>)
Sets the globals segment for the WebAssembly module to be built.
Sourcepub fn add_global(&mut self, global: Global) -> Result<GlobalIndex, ModelError>
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.
Sourcepub fn set_elements(&mut self, elements: Option<Vec<Element>>)
pub fn set_elements(&mut self, elements: Option<Vec<Element>>)
Sets the elements segment for the WebAssembly module to be built.
Sourcepub fn add_element(
&mut self,
element: Element,
) -> Result<ElementIndex, ModelError>
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.
Sourcepub fn set_data(&mut self, data: Option<Vec<Data>>)
pub fn set_data(&mut self, data: Option<Vec<Data>>)
Sets the data segment for the WebAssembly module to be built.
Sourcepub fn add_data(&mut self, datum: Data) -> Result<DataIndex, ModelError>
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.
Sourcepub fn set_start(&mut self, start: Option<Start>)
pub fn set_start(&mut self, start: Option<Start>)
Sets the start segment for the WebAssembly module to be built.
Sourcepub fn set_imports(&mut self, imports: Option<Vec<Import>>)
pub fn set_imports(&mut self, imports: Option<Vec<Import>>)
Sets the imports segment for the WebAssembly module to be built.
Sourcepub fn add_import(&mut self, import: Import) -> Result<u32, ModelError>
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).
Sourcepub fn set_exports(&mut self, exports: Option<Vec<Export>>)
pub fn set_exports(&mut self, exports: Option<Vec<Export>>)
Sets the exports segment for the WebAssembly module to be built.
Sourcepub fn add_export(&mut self, export: Export)
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.
Sourcepub fn set_custom_sections(
&mut self,
insertion_point: ModuleSection,
custom_sections: Option<Vec<Custom>>,
)
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.
Sourcepub fn add_custom_section(
&mut self,
insertion_point: ModuleSection,
custom_section: Custom,
)
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.
Sourcepub fn set_data_count(&mut self, data_count: Option<u32>)
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.
Sourcepub fn include_data_count(&mut self)
pub fn include_data_count(&mut self)
Includes a data count based on the number of data segments currently in this builder.
Sourcepub fn function_types(&self) -> Option<&[FunctionType]>
pub fn function_types(&self) -> Option<&[FunctionType]>
The 𝗍𝗒𝗉𝖾𝗌 component of the module to be built.
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 the module to be built.