/// A WebAssembly component section. /// /// Various builders defined in this crate already implement this trait, but you /// can also implement it yourself for your own custom section builders, or use /// `RawSection` to use a bunch of raw bytes as a section. pubtrait ComponentSection: Encode { /// Gets the section identifier for this section. fn id(&self) -> u8;
/// Appends this section to the specified destination list of bytes. fn append_to_component(&self, dst: &mutVec<u8>) {
dst.push(self.id()); self.encode(dst);
}
}
/// Known section identifiers of WebAssembly components. /// /// These sections are supported by the component model proposal. #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)] #[repr(u8)] pubenum ComponentSectionId { /// The section is a core custom section.
CoreCustom = 0, /// The section is a core module section.
CoreModule = 1, /// The section is a core instance section.
CoreInstance = 2, /// The section is a core type section.
CoreType = 3, /// The section is a component section.
Component = 4, /// The section is an instance section.
Instance = 5, /// The section is an alias section.
Alias = 6, /// The section is a type section. Type = 7, /// The section is a canonical function section.
CanonicalFunction = 8, /// The section is a start section.
Start = 9, /// The section is an import section.
Import = 10, /// The section is an export section.
Export = 11,
}
impl From<ComponentSectionId> for u8 { #[inline] fn from(id: ComponentSectionId) -> u8 {
id as u8
}
}
/// Represents a WebAssembly component that is being encoded. /// /// Unlike core WebAssembly modules, the sections of a component /// may appear in any order and may be repeated. /// /// Components may also added as a section to other components. #[derive(Clone, Debug)] pubstruct Component {
bytes: Vec<u8>,
}
impl Component { /// The 8-byte header at the beginning of all components. #[rustfmt::skip] pubconst HEADER: [u8; 8] = [ // Magic 0x00, 0x61, 0x73, 0x6D, // Version 0x0d, 0x00, 0x01, 0x00,
];
/// Begin writing a new `Component`. pubfn new() -> Self { Self {
bytes: Self::HEADER.to_vec(),
}
}
/// Finish writing this component and extract ownership of the encoded bytes. pubfn finish(self) -> Vec<u8> { self.bytes
}
/// Write a section to this component. pubfn section(&mutself, section: &impl ComponentSection) -> &mutSelf { self.bytes.push(section.id());
section.encode(&mutself.bytes); self
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.