/src/wasm-tools/crates/wasm-encoder/src/start.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use super::*; |
2 | | |
3 | | /// An encoder for the start section. |
4 | | /// |
5 | | /// # Example |
6 | | /// |
7 | | /// Note: this doesn't actually define the function at index 0, its type, or its |
8 | | /// code body, so the resulting Wasm module will be invalid. See `TypeSection`, |
9 | | /// `FunctionSection`, and `CodeSection` for details on how to generate those |
10 | | /// things. |
11 | | /// |
12 | | /// ``` |
13 | | /// use wasm_encoder::{Module, StartSection}; |
14 | | /// |
15 | | /// let start = StartSection { function_index: 0 }; |
16 | | /// |
17 | | /// let mut module = Module::new(); |
18 | | /// module.section(&start); |
19 | | /// |
20 | | /// let wasm_bytes = module.finish(); |
21 | | /// ``` |
22 | 0 | #[derive(Clone, Copy, Debug)] |
23 | | pub struct StartSection { |
24 | | /// The index of the start function. |
25 | | pub function_index: u32, |
26 | | } |
27 | | |
28 | | impl Section for StartSection { |
29 | 10.9k | fn id(&self) -> u8 { |
30 | 10.9k | SectionId::Start.into() |
31 | 10.9k | } |
32 | | |
33 | 10.9k | fn encode<S>(&self, sink: &mut S) |
34 | 10.9k | where |
35 | 10.9k | S: Extend<u8>, |
36 | 10.9k | { |
37 | 10.9k | let f = encoders::u32(self.function_index); |
38 | 10.9k | let n = f.len(); |
39 | 10.9k | sink.extend(encoders::u32(n as u32).chain(f)); |
40 | 10.9k | } |
41 | | } |