tinywasm_wasmparser/readers/component/
start.rs

1use alloc::boxed::Box;
2
3use crate::limits::{MAX_WASM_FUNCTION_RETURNS, MAX_WASM_START_ARGS};
4use crate::{BinaryReader, FromReader, Result};
5
6/// Represents the start function in a WebAssembly component.
7#[derive(Debug, Clone)]
8pub struct ComponentStartFunction {
9    /// The index to the start function.
10    pub func_index: u32,
11    /// The start function arguments.
12    ///
13    /// The arguments are specified by value index.
14    pub arguments: Box<[u32]>,
15    /// The number of expected results for the start function.
16    pub results: u32,
17}
18
19impl<'a> FromReader<'a> for ComponentStartFunction {
20    fn from_reader(reader: &mut BinaryReader<'a>) -> Result<Self> {
21        let func_index = reader.read_var_u32()?;
22        let arguments = reader
23            .read_iter(MAX_WASM_START_ARGS, "start function arguments")?
24            .collect::<Result<_>>()?;
25        let results = reader.read_size(MAX_WASM_FUNCTION_RETURNS, "start function results")? as u32;
26        Ok(ComponentStartFunction {
27            func_index,
28            arguments,
29            results,
30        })
31    }
32}