pub struct ComponentBuilder { /* private fields */ }
component-model
only.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
impl ComponentBuilder
sourcepub fn core_module_count(&self) -> u32
pub fn core_module_count(&self) -> u32
Returns the current number of core modules.
sourcepub fn core_func_count(&self) -> u32
pub fn core_func_count(&self) -> u32
Returns the current number of core funcs.
sourcepub fn core_type_count(&self) -> u32
pub fn core_type_count(&self) -> u32
Returns the current number of core types.
sourcepub fn core_memory_count(&self) -> u32
pub fn core_memory_count(&self) -> u32
Returns the current number of core memories.
sourcepub fn core_table_count(&self) -> u32
pub fn core_table_count(&self) -> u32
Returns the current number of core tables.
sourcepub fn core_instance_count(&self) -> u32
pub fn core_instance_count(&self) -> u32
Returns the current number of core instances.
sourcepub fn core_tag_count(&self) -> u32
pub fn core_tag_count(&self) -> u32
Returns the current number of core tags.
sourcepub fn core_global_count(&self) -> u32
pub fn core_global_count(&self) -> u32
Returns the current number of core globals.
sourcepub fn func_count(&self) -> u32
pub fn func_count(&self) -> u32
Returns the current number of component funcs.
sourcepub fn instance_count(&self) -> u32
pub fn instance_count(&self) -> u32
Returns the current number of component instances.
sourcepub fn value_count(&self) -> u32
pub fn value_count(&self) -> u32
Returns the current number of component values.
sourcepub fn component_count(&self) -> u32
pub fn component_count(&self) -> u32
Returns the current number of components.
sourcepub fn type_count(&self) -> u32
pub fn type_count(&self) -> u32
Returns the current number of component types.
sourcepub fn finish(self) -> Vec<u8>
pub fn finish(self) -> Vec<u8>
Completes this component and returns the binary encoding of the entire component.
sourcepub fn core_module(&mut self, module: &Module) -> u32
pub fn core_module(&mut self, module: &Module) -> u32
Encodes a core wasm Module
into this component, returning its index.
sourcepub fn core_module_raw(&mut self, module: &[u8]) -> u32
pub fn core_module_raw(&mut self, module: &[u8]) -> u32
Encodes a core wasm module
into this component, returning its index.
sourcepub fn core_instantiate<'a, A>(&mut self, module_index: u32, args: A) -> u32
pub fn core_instantiate<'a, A>(&mut self, module_index: u32, args: A) -> u32
Instantiates a core wasm module at module_index
with the args
provided.
Returns the index of the core wasm instance crated.
sourcepub fn core_instantiate_exports<'a, E>(&mut self, exports: E) -> u32
pub fn core_instantiate_exports<'a, E>(&mut self, exports: E) -> u32
Creates a new core wasm instance from the exports
provided.
Returns the index of the core wasm instance crated.
sourcepub fn core_alias_export(
&mut self,
instance: u32,
name: &str,
kind: ExportKind,
) -> u32
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.
sourcepub fn alias_export(
&mut self,
instance: u32,
name: &str,
kind: ComponentExportKind,
) -> u32
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.
sourcepub fn lower_func<O>(&mut self, func_index: u32, options: O) -> u32
pub fn lower_func<O>(&mut self, func_index: u32, options: O) -> u32
Lowers the func_index
component function into a core wasm function
using the options
provided.
Returns the index of the core wasm function created.
sourcepub fn lift_func<O>(
&mut self,
core_func_index: u32,
type_index: u32,
options: O,
) -> u32
pub fn lift_func<O>( &mut self, core_func_index: u32, type_index: u32, options: O, ) -> u32
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.
sourcepub fn import(&mut self, name: &str, ty: ComponentTypeRef) -> u32
pub fn import(&mut self, name: &str, ty: ComponentTypeRef) -> u32
Imports a new item into this component with the name
and ty
specified.
sourcepub fn export(
&mut self,
name: &str,
kind: ComponentExportKind,
idx: u32,
ty: Option<ComponentTypeRef>,
) -> u32
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.
sourcepub fn core_type(&mut self) -> (u32, ComponentCoreTypeEncoder<'_>)
pub fn core_type(&mut self) -> (u32, ComponentCoreTypeEncoder<'_>)
Creates a new encoder for the next core type in this component.
sourcepub fn ty(&mut self) -> (u32, ComponentTypeEncoder<'_>)
pub fn ty(&mut self) -> (u32, ComponentTypeEncoder<'_>)
Creates a new encoder for the next type in this component.
sourcepub fn type_instance(&mut self, ty: &InstanceType) -> u32
pub fn type_instance(&mut self, ty: &InstanceType) -> u32
Creates a new instance type within this component.
sourcepub fn type_component(&mut self, ty: &ComponentType) -> u32
pub fn type_component(&mut self, ty: &ComponentType) -> u32
Creates a new component type within this component.
sourcepub fn type_defined(&mut self) -> (u32, ComponentDefinedTypeEncoder<'_>)
pub fn type_defined(&mut self) -> (u32, ComponentDefinedTypeEncoder<'_>)
Creates a new defined component type within this component.
sourcepub fn type_function(&mut self) -> (u32, ComponentFuncTypeEncoder<'_>)
pub fn type_function(&mut self) -> (u32, ComponentFuncTypeEncoder<'_>)
Creates a new component function type within this component.
sourcepub fn component(&mut self, builder: ComponentBuilder) -> u32
pub fn component(&mut self, builder: ComponentBuilder) -> u32
Defines a new subcomponent of this component.
sourcepub fn component_raw(&mut self, data: &[u8]) -> u32
pub fn component_raw(&mut self, data: &[u8]) -> u32
Defines a new subcomponent of this component.
sourcepub fn instantiate<A, S>(&mut self, component_index: u32, args: A) -> u32where
A: IntoIterator<Item = (S, ComponentExportKind, u32)>,
A::IntoIter: ExactSizeIterator,
S: AsRef<str>,
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.
sourcepub fn resource_drop(&mut self, ty: u32) -> u32
pub fn resource_drop(&mut self, ty: u32) -> u32
Declares a new resource.drop
intrinsic.
sourcepub fn resource_new(&mut self, ty: u32) -> u32
pub fn resource_new(&mut self, ty: u32) -> u32
Declares a new resource.new
intrinsic.
sourcepub fn resource_rep(&mut self, ty: u32) -> u32
pub fn resource_rep(&mut self, ty: u32) -> u32
Declares a new resource.rep
intrinsic.
sourcepub fn thread_spawn(&mut self, ty: u32) -> u32
pub fn thread_spawn(&mut self, ty: u32) -> u32
Declares a new thread.spawn
intrinsic.
sourcepub fn thread_hw_concurrency(&mut self) -> u32
pub fn thread_hw_concurrency(&mut self) -> u32
Declares a new thread.hw_concurrency
intrinsic.
sourcepub fn custom_section(&mut self, section: &CustomSection<'_>)
pub fn custom_section(&mut self, section: &CustomSection<'_>)
Adds a new custom section to this component.
sourcepub fn raw_custom_section(&mut self, section: &[u8])
pub fn raw_custom_section(&mut self, section: &[u8])
Adds a new custom section to this component.