Struct parity_wasm::builder::ModuleBuilder

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

Module builder

Implementations§

source§

impl ModuleBuilder

source

pub fn new() -> Self

New empty module builder

source§

impl<F> ModuleBuilder<F>
where F: Invoke<Module>,

source

pub fn with_callback(callback: F) -> Self

New module builder with bound callback

source

pub fn with_module(self, module: Module) -> Self

Builder from raw module

source

pub fn with_sections<I>(self, sections: I) -> Self
where I: IntoIterator<Item = Section>,

Fill module with sections from iterator

source

pub fn with_section(self, section: Section) -> Self

Add additional section

source

pub fn with_signatures(self, bindings: Vec<Signature>) -> Self

Binds to the type section, creates additional types when required

source

pub fn push_function(&mut self, func: FunctionDefinition) -> CodeLocation

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

source

pub fn push_memory(&mut self, memory: MemoryDefinition) -> u32

Push linear memory region

source

pub fn push_table(&mut self, table: TableDefinition) -> u32

Push table

source

pub fn push_global(&mut self, global: GlobalEntry) -> u32

Push global.

source

pub fn push_signature(&mut self, signature: Signature) -> u32

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

source

pub fn push_signatures(&mut self, signatures: Vec<Signature>) -> Vec<u32>

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

source

pub fn push_import(&mut self, import: ImportEntry) -> u32

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

source

pub fn push_export(&mut self, export: ExportEntry) -> u32

Push export entry to module.

source

pub fn function(self) -> FunctionBuilder<Self>

Add new function using dedicated builder

source

pub fn memory(self) -> MemoryBuilder<Self>

Add new linear memory using dedicated builder

source

pub fn table(self) -> TableBuilder<Self>

Add new table using dedicated builder

source

pub fn functions(self) -> SignaturesBuilder<Self>

Define functions section

source

pub fn with_export(self, entry: ExportEntry) -> Self

With inserted export entry

source

pub fn with_import(self, entry: ImportEntry) -> Self

With inserted import entry

source

pub fn import(self) -> ImportBuilder<Self>

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);
source

pub fn with_global(self, global: GlobalEntry) -> Self

With global variable

source

pub fn with_table(self, table: TableType) -> Self

With table

source

pub fn export(self) -> ExportBuilder<Self>

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);
source

pub fn global(self) -> GlobalBuilder<Self>

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);
source

pub fn with_data_segment(self, segment: DataSegment) -> Self

Add data segment to the builder

source

pub fn data(self) -> DataSegmentBuilder<Self>

Data entry builder

source

pub fn build(self) -> F::Result

Build module (final step)

Trait Implementations§

source§

impl Default for ModuleBuilder

source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<F> Freeze for ModuleBuilder<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for ModuleBuilder<F>
where F: RefUnwindSafe,

§

impl<F> Send for ModuleBuilder<F>
where F: Send,

§

impl<F> Sync for ModuleBuilder<F>
where F: Sync,

§

impl<F> Unpin for ModuleBuilder<F>
where F: Unpin,

§

impl<F> UnwindSafe for ModuleBuilder<F>
where F: UnwindSafe,

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

§

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

§

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.