1 | use crate::{ComponentSection, ComponentSectionId, Encode, Module}; |
2 | |
3 | /// An encoder for the module section of WebAssembly components. |
4 | /// |
5 | /// # Example |
6 | /// |
7 | /// ```rust |
8 | /// use wasm_encoder::{Module, Component, ModuleSection}; |
9 | /// |
10 | /// let mut module = Module::new(); |
11 | /// let mut component = Component::new(); |
12 | /// component.section(&ModuleSection(&module)); |
13 | /// |
14 | /// let bytes = component.finish(); |
15 | /// ``` |
16 | #[derive (Clone, Debug)] |
17 | pub struct ModuleSection<'a>(pub &'a Module); |
18 | |
19 | impl Encode for ModuleSection<'_> { |
20 | fn encode(&self, sink: &mut Vec<u8>) { |
21 | self.0.bytes.encode(sink); |
22 | } |
23 | } |
24 | |
25 | impl ComponentSection for ModuleSection<'_> { |
26 | fn id(&self) -> u8 { |
27 | ComponentSectionId::CoreModule.into() |
28 | } |
29 | } |
30 | |