summaryrefslogtreecommitdiffstats
path: root/third_party/rust/wasm-encoder/src/component/modules.rs
blob: 437cd353afd4c922dab1963f0ebb008004ea7dec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::{ComponentSection, ComponentSectionId, Encode, Module};

/// An encoder for the module section of WebAssembly components.
///
/// # Example
///
/// ```rust
/// use wasm_encoder::{Module, Component, ModuleSection};
///
/// let mut module = Module::new();
/// let mut component = Component::new();
/// component.section(&ModuleSection(&module));
///
/// let bytes = component.finish();
/// ```
#[derive(Clone, Debug)]
pub struct ModuleSection<'a>(pub &'a Module);

impl Encode for ModuleSection<'_> {
    fn encode(&self, sink: &mut Vec<u8>) {
        self.0.bytes.encode(sink);
    }
}

impl ComponentSection for ModuleSection<'_> {
    fn id(&self) -> u8 {
        ComponentSectionId::CoreModule.into()
    }
}