pub struct ComponentBuilder { /* private fields */ }
Expand description

Convenience type to build a component incrementally and automatically keep track of index spaces.

This type is intended to be a wrapper around the Component encoding type which is useful for building it up incrementally over time. This type will automatically collect definitions into sections and reports the index of all items added by keeping track of indices internally.

Implementations§

source§

impl ComponentBuilder

source

pub fn core_module_count(&self) -> u32

Returns the current number of core modules.

source

pub fn core_func_count(&self) -> u32

Returns the current number of core funcs.

source

pub fn core_type_count(&self) -> u32

Returns the current number of core types.

source

pub fn core_memory_count(&self) -> u32

Returns the current number of core memories.

source

pub fn core_table_count(&self) -> u32

Returns the current number of core tables.

source

pub fn core_instance_count(&self) -> u32

Returns the current number of core instances.

source

pub fn core_tag_count(&self) -> u32

Returns the current number of core tags.

source

pub fn core_global_count(&self) -> u32

Returns the current number of core globals.

source

pub fn func_count(&self) -> u32

Returns the current number of component funcs.

source

pub fn instance_count(&self) -> u32

Returns the current number of component instances.

source

pub fn value_count(&self) -> u32

Returns the current number of component values.

source

pub fn component_count(&self) -> u32

Returns the current number of components.

source

pub fn type_count(&self) -> u32

Returns the current number of component types.

source

pub fn finish(self) -> Vec<u8>

Completes this component and returns the binary encoding of the entire component.

source

pub fn core_module(&mut self, module: &Module) -> u32

Encodes a core wasm Module into this component, returning its index.

source

pub fn core_module_raw(&mut self, module: &[u8]) -> u32

Encodes a core wasm module into this component, returning its index.

source

pub fn core_instantiate<'a, A>(&mut self, module_index: u32, args: A) -> u32where A: IntoIterator<Item = (&'a str, ModuleArg)>, A::IntoIter: ExactSizeIterator,

Instantiates a core wasm module at module_index with the args provided.

Returns the index of the core wasm instance crated.

source

pub fn core_instantiate_exports<'a, E>(&mut self, exports: E) -> u32where E: IntoIterator<Item = (&'a str, ExportKind, u32)>, E::IntoIter: ExactSizeIterator,

Creates a new core wasm instance from the exports provided.

Returns the index of the core wasm instance crated.

source

pub fn core_alias_export( &mut self, instance: u32, name: &str, kind: ExportKind ) -> u32

Creates a new aliased item where the core instance specified has its export name aliased out with the kind specified.

Returns the index of the item crated.

source

pub fn alias(&mut self, alias: Alias<'_>) -> u32

Adds a new alias to this component

source

pub fn alias_export( &mut self, instance: u32, name: &str, kind: ComponentExportKind ) -> u32

Creates an alias to a previous component instance’s exported item.

The instance provided is the instance to access and the name is the item to access.

Returns the index of the new item defined.

source

pub fn lower_func<O>(&mut self, func_index: u32, options: O) -> u32where O: IntoIterator<Item = CanonicalOption>, O::IntoIter: ExactSizeIterator,

Lowers the func_index component function into a core wasm function using the options provided.

Returns the index of the core wasm function created.

source

pub fn lift_func<O>( &mut self, core_func_index: u32, type_index: u32, options: O ) -> u32where O: IntoIterator<Item = CanonicalOption>, O::IntoIter: ExactSizeIterator,

Lifts the core wasm core_func_index function with the component function type type_index and options.

Returns the index of the component function created.

source

pub fn import(&mut self, name: &str, ty: ComponentTypeRef) -> u32

Imports a new item into this component with the name and ty specified.

source

pub fn export( &mut self, name: &str, kind: ComponentExportKind, idx: u32, ty: Option<ComponentTypeRef> ) -> u32

Exports a new item from this component with the name and kind specified.

The idx is the item to export and the ty is an optional type to ascribe to the export.

source

pub fn core_type(&mut self) -> (u32, CoreTypeEncoder<'_>)

Creates a new encoder for the next core type in this component.

source

pub fn ty(&mut self) -> (u32, ComponentTypeEncoder<'_>)

Creates a new encoder for the next type in this component.

source

pub fn type_instance(&mut self, ty: &InstanceType) -> u32

Creates a new instance type within this component.

source

pub fn type_component(&mut self, ty: &ComponentType) -> u32

Creates a new component type within this component.

source

pub fn type_defined(&mut self) -> (u32, ComponentDefinedTypeEncoder<'_>)

Creates a new defined component type within this component.

source

pub fn type_function(&mut self) -> (u32, ComponentFuncTypeEncoder<'_>)

Creates a new component function type within this component.

source

pub fn type_resource(&mut self, rep: ValType, dtor: Option<u32>) -> u32

Declares a

source

pub fn component(&mut self, builder: ComponentBuilder) -> u32

Defines a new subcomponent of this component.

source

pub fn component_raw(&mut self, data: &[u8]) -> u32

Defines a new subcomponent of this component.

source

pub fn instantiate<A, S>(&mut self, component_index: u32, args: A) -> u32where A: IntoIterator<Item = (S, ComponentExportKind, u32)>, A::IntoIter: ExactSizeIterator, S: AsRef<str>,

Instantiates the component_index specified with the args specified.

source

pub fn resource_drop(&mut self, ty: u32) -> u32

Declares a new resource.drop intrinsic.

source

pub fn resource_new(&mut self, ty: u32) -> u32

Declares a new resource.new intrinsic.

source

pub fn resource_rep(&mut self, ty: u32) -> u32

Declares a new resource.rep intrinsic.

source

pub fn custom_section(&mut self, section: &CustomSection<'_>)

Adds a new custom section to this component.

source

pub fn raw_custom_section(&mut self, section: &[u8])

Adds a new custom section to this component.

Trait Implementations§

source§

impl Debug for ComponentBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ComponentBuilder

source§

fn default() -> ComponentBuilder

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

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.