wasm_encoder

Struct ComponentBuilder

Source
pub struct ComponentBuilder { /* private fields */ }
Available on crate feature 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

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) -> u32
where 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) -> u32
where 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) -> 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.

Source

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.

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, ComponentCoreTypeEncoder<'_>)

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) -> u32

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 thread_spawn(&mut self, ty: u32) -> u32

Declares a new thread.spawn intrinsic.

Source

pub fn thread_hw_concurrency(&mut self) -> u32

Declares a new thread.hw_concurrency 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 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>,

Source§

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

Source§

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.