/rust/registry/src/index.crates.io-6f17d22bba15001f/wasm-encoder-0.25.0/src/component/start.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use crate::{ComponentSection, ComponentSectionId, Encode}; |
2 | | |
3 | | /// An encoder for the start section of WebAssembly components. |
4 | | /// |
5 | | /// # Example |
6 | | /// |
7 | | /// ``` |
8 | | /// use wasm_encoder::{Component, ComponentStartSection}; |
9 | | /// |
10 | | /// let start = ComponentStartSection { function_index: 0, args: [0, 1], results: 1 }; |
11 | | /// |
12 | | /// let mut component = Component::new(); |
13 | | /// component.section(&start); |
14 | | /// |
15 | | /// let bytes = component.finish(); |
16 | | /// ``` |
17 | 0 | #[derive(Clone, Debug)] |
18 | | pub struct ComponentStartSection<A> { |
19 | | /// The index to the start function. |
20 | | pub function_index: u32, |
21 | | /// The arguments to pass to the start function. |
22 | | /// |
23 | | /// An argument is an index to a value. |
24 | | pub args: A, |
25 | | /// The number of expected results for the start function. |
26 | | /// |
27 | | /// This should match the number of results for the type of |
28 | | /// the function referenced by `function_index`. |
29 | | pub results: u32, |
30 | | } |
31 | | |
32 | | impl<A> Encode for ComponentStartSection<A> |
33 | | where |
34 | | A: AsRef<[u32]>, |
35 | | { |
36 | 0 | fn encode(&self, sink: &mut Vec<u8>) { |
37 | 0 | let mut bytes = Vec::new(); |
38 | 0 | self.function_index.encode(&mut bytes); |
39 | 0 | self.args.as_ref().encode(&mut bytes); |
40 | 0 | self.results.encode(&mut bytes); |
41 | 0 | bytes.encode(sink); |
42 | 0 | } Unexecuted instantiation: <wasm_encoder::component::start::ComponentStartSection<alloc::vec::Vec<u32>> as wasm_encoder::Encode>::encode Unexecuted instantiation: <wasm_encoder::component::start::ComponentStartSection<_> as wasm_encoder::Encode>::encode |
43 | | } |
44 | | |
45 | | impl<A> ComponentSection for ComponentStartSection<A> |
46 | | where |
47 | | A: AsRef<[u32]>, |
48 | | { |
49 | 0 | fn id(&self) -> u8 { |
50 | 0 | ComponentSectionId::Start.into() |
51 | 0 | } Unexecuted instantiation: <wasm_encoder::component::start::ComponentStartSection<alloc::vec::Vec<u32>> as wasm_encoder::component::ComponentSection>::id Unexecuted instantiation: <wasm_encoder::component::start::ComponentStartSection<_> as wasm_encoder::component::ComponentSection>::id |
52 | | } |