Debian Codegraph @

crates/wasm-encoder/src/component/modules.rs

raw
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 fn encode(&self, sink: &mut Vec<u8>) {
22 self.0.bytes.encode(sink);
23 }
24 }
25
26 impl ComponentSection for ModuleSection<'_> {
27 fn id(&self) -> u8 {
28 ComponentSectionId::CoreModule.into()
29 }
30 }