wasmparser/readers/component/
start.rs

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