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