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