pub struct ModuleBuilder<F = Identity> { /* private fields */ }
Expand description

Module builder

Implementations

New empty module builder

New module builder with bound callback

Builder from raw module

Fill module with sections from iterator

Add additional section

Binds to the type section, creates additional types when required

Push stand-alone function definition, creating sections, signature and code blocks in corresponding sections. FunctionDefinition can be build using builder::function builder

Push linear memory region

Push table

Push one function signature, returning it’s calling index. Can create corresponding type in type section.

Push signatures in the module, returning corresponding indices of pushed signatures

Push import entry to module. Note that this does not update calling indices in function bodies.

Push export entry to module.

Add new function using dedicated builder

Add new linear memory using dedicated builder

Add new table using dedicated builder

Define functions section

With inserted export entry

With inserted import entry

Import entry builder

Examples
use parity_wasm::builder::module;

let module = module()
   .import()
       .module("env")
       .field("memory")
       .external().memory(256, Some(256))
       .build()
   .build();

assert_eq!(module.import_section().expect("import section to exist").entries().len(), 1);

With global variable

With table

Export entry builder

Examples
use parity_wasm::builder::module;
use parity_wasm::elements::Instruction::*;

let module = module()
   .global()
        .value_type().i32()
        .init_expr(I32Const(0))
        .build()
   .export()
       .field("_zero")
       .internal().global(0)
       .build()
   .build();

assert_eq!(module.export_section().expect("export section to exist").entries().len(), 1);

Glboal entry builder

Examples
use parity_wasm::builder::module;
use parity_wasm::elements::Instruction::*;

let module = module()
   .global()
        .value_type().i32()
        .init_expr(I32Const(0))
        .build()
   .build();

assert_eq!(module.global_section().expect("global section to exist").entries().len(), 1);

Add data segment to the builder

Data entry builder

Build module (final step)

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.