Coverage Report

Created: 2021-03-22 08:29

/rust/registry/src/github.com-1ecc6299db9ec823/wasm-encoder-0.4.0/src/start.rs
Line
Count
Source
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
pub struct StartSection {
23
    /// The index of the start function.
24
    pub function_index: u32,
25
}
26
27
impl Section for StartSection {
28
1.75k
    fn id(&self) -> u8 {
29
1.75k
        SectionId::Start.into()
30
1.75k
    }
31
32
1.75k
    fn encode<S>(&self, sink: &mut S)
33
1.75k
    where
34
1.75k
        S: Extend<u8>,
35
1.75k
    {
36
1.75k
        let f = encoders::u32(self.function_index);
37
1.75k
        let n = f.len();
38
1.75k
        sink.extend(encoders::u32(n as u32).chain(f));
39
1.75k
    }
40
}