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