mod aliases;
mod components;
mod exports;
mod functions;
mod imports;
mod instances;
mod modules;
mod start;
mod types;
pub use self::aliases::*;
pub use self::components::*;
pub use self::exports::*;
pub use self::functions::*;
pub use self::imports::*;
pub use self::instances::*;
pub use self::modules::*;
pub use self::start::*;
pub use self::types::*;
use crate::Encode;
pub trait ComponentSection: Encode {}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
#[repr(u8)]
pub enum ComponentSectionId {
Custom = 0,
Type = 1,
Import = 2,
Function = 3,
Module = 4,
Component = 5,
Instance = 6,
Export = 7,
Start = 8,
Alias = 9,
}
impl From<ComponentSectionId> for u8 {
#[inline]
fn from(id: ComponentSectionId) -> u8 {
id as u8
}
}
impl Encode for ComponentSectionId {
fn encode(&self, sink: &mut Vec<u8>) {
sink.push(*self as u8);
}
}
#[derive(Clone, Debug)]
pub struct Component {
bytes: Vec<u8>,
}
impl Component {
pub fn new() -> Self {
Self {
bytes: vec![
0x00, 0x61, 0x73, 0x6D, 0x0a, 0x00, 0x01, 0x00, ],
}
}
pub fn finish(self) -> Vec<u8> {
self.bytes
}
pub fn section(&mut self, section: &impl ComponentSection) -> &mut Self {
section.encode(&mut self.bytes);
self
}
}
impl Default for Component {
fn default() -> Self {
Self::new()
}
}