Struct wasm_encoder::ElementSection
source · pub struct ElementSection { /* private fields */ }
Expand description
An encoder for the element section.
Element sections are only supported for modules.
Example
use wasm_encoder::{
Elements, ElementSection, Module, TableSection, TableType,
ValType, ConstExpr
};
let mut tables = TableSection::new();
tables.table(TableType {
element_type: ValType::FuncRef,
minimum: 128,
maximum: None,
});
let mut elements = ElementSection::new();
let table_index = 0;
let offset = ConstExpr::i32_const(42);
let element_type = ValType::FuncRef;
let functions = Elements::Functions(&[
// Function indices...
]);
elements.active(Some(table_index), &offset, element_type, functions);
let mut module = Module::new();
module
.section(&tables)
.section(&elements);
let wasm_bytes = module.finish();
Implementations§
source§impl ElementSection
impl ElementSection
sourcepub fn segment<'a>(&mut self, segment: ElementSegment<'a>) -> &mut Self
pub fn segment<'a>(&mut self, segment: ElementSegment<'a>) -> &mut Self
Define an element segment.
sourcepub fn active(
&mut self,
table_index: Option<u32>,
offset: &ConstExpr,
element_type: ValType,
elements: Elements<'_>
) -> &mut Self
pub fn active( &mut self, table_index: Option<u32>, offset: &ConstExpr, element_type: ValType, elements: Elements<'_> ) -> &mut Self
Define an active element segment.
Active
element specifying a None
table forces the MVP encoding and refers to the 0th
table holding funcref
s. Non-None
tables use the encoding introduced with the bulk
memory proposal and can refer to tables with any valid reference type.
sourcepub fn passive<'a>(
&mut self,
element_type: ValType,
elements: Elements<'a>
) -> &mut Self
pub fn passive<'a>( &mut self, element_type: ValType, elements: Elements<'a> ) -> &mut Self
Encode a passive element segment.
Passive segments are part of the bulk memory proposal.
Trait Implementations§
source§impl Clone for ElementSection
impl Clone for ElementSection
source§fn clone(&self) -> ElementSection
fn clone(&self) -> ElementSection
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for ElementSection
impl Debug for ElementSection
source§impl Default for ElementSection
impl Default for ElementSection
source§fn default() -> ElementSection
fn default() -> ElementSection
Returns the “default value” for a type. Read more