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.