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