pub trait Parseable<'a, Ctx>: Sized {
// Required method
fn parse(ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>;
}
Expand description
A trait for parsing data. The lifetime and context are useful when we want to parse data without copying, which is useful to avoid copying all the unparsed sections.
The implementors of this trait will generally parse data according to the format specified by Wasm specification.
Required Methods§
Sourcefn parse(ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>
fn parse(ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>
Read a value from the cursor, or signal error. This function is responsible for advancing the cursor in-line with the data it has read.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl<'a, Ctx> Parseable<'a, Ctx> for &'a [ValueType]
Same as the instance for Vec<u8>
, with the difference that no data
is copied and the result is a reference to the initial byte array.
impl<'a, Ctx> Parseable<'a, Ctx> for &'a [ValueType]
Same as the instance for Vec<u8>
, with the difference that no data
is copied and the result is a reference to the initial byte array.
Source§impl<'a, Ctx> Parseable<'a, Ctx> for &'a [u8]
Same as the instance for Vec<u8>
, with the difference that no data
is copied and the result is a reference to the initial byte array.
impl<'a, Ctx> Parseable<'a, Ctx> for &'a [u8]
Same as the instance for Vec<u8>
, with the difference that no data
is copied and the result is a reference to the initial byte array.
Source§impl<'a, Ctx> Parseable<'a, Ctx> for i32
Implementation for i32 according to the Wasm specification.
impl<'a, Ctx> Parseable<'a, Ctx> for i32
Implementation for i32 according to the Wasm specification.
Source§impl<'a, Ctx> Parseable<'a, Ctx> for i64
Implementation for i64 according to the Wasm specification.
impl<'a, Ctx> Parseable<'a, Ctx> for i64
Implementation for i64 according to the Wasm specification.
Source§impl<'a, Ctx> Parseable<'a, Ctx> for u16
Implementation for u16 according to the Wasm specification.
impl<'a, Ctx> Parseable<'a, Ctx> for u16
Implementation for u16 according to the Wasm specification.
Source§impl<'a, Ctx> Parseable<'a, Ctx> for u32
Implementation for u32 according to the Wasm specification.
impl<'a, Ctx> Parseable<'a, Ctx> for u32
Implementation for u32 according to the Wasm specification.
Source§impl<'a, Ctx> Parseable<'a, Ctx> for u64
Implementation for u64 according to the Wasm specification.
impl<'a, Ctx> Parseable<'a, Ctx> for u64
Implementation for u64 according to the Wasm specification.
Source§impl<'a, Ctx: Copy, A: Parseable<'a, Ctx>> Parseable<'a, Ctx> for Option<A>
Special case of a vector where we only expect 0 or 1 elements.
impl<'a, Ctx: Copy, A: Parseable<'a, Ctx>> Parseable<'a, Ctx> for Option<A>
Special case of a vector where we only expect 0 or 1 elements.
Source§impl<'a, Ctx: Copy, A: Parseable<'a, Ctx>> Parseable<'a, Ctx> for Vec<A>
Parse a vector of elements according to the Wasm specification.
Specifically this is parsed by reading the length as a u32 and then reading
that many elements.
impl<'a, Ctx: Copy, A: Parseable<'a, Ctx>> Parseable<'a, Ctx> for Vec<A>
Parse a vector of elements according to the Wasm specification. Specifically this is parsed by reading the length as a u32 and then reading that many elements.
Implementors§
impl<'a> Parseable<'a, ValidationConfig> for Global
impl<'a> Parseable<'a, ValidationConfig> for GlobalSection
impl<'a, Ctx> Parseable<'a, Ctx> for ArtifactVersion
impl<'a, Ctx> Parseable<'a, Ctx> for BlockType
The version of Wasm we support only has the empty block type, the I32, and I64 types. Type indices are not supported.
impl<'a, Ctx> Parseable<'a, Ctx> for ValueType
Parse a value type. The Wasm version we support does not have floating point types, so we disallow them already at the parsing stage.
impl<'a, Ctx> Parseable<'a, Ctx> for SectionId
Parsing of the section ID according to the linked Wasm specification.
impl<'a, Ctx> Parseable<'a, Ctx> for Name
Parse a name as specified by the Wasm specification, with our own restrictions. The restriction we impose is that the name consists solely of ASCII characters.
impl<'a, Ctx> Parseable<'a, Ctx> for StartSection
impl<'a, Ctx> Parseable<'a, Ctx> for Byte
Parse a single byte.
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ExportDescription
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ImportDescription
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ArtifactData
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ArtifactLocal
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ArtifactMemory
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ArtifactNamedImport
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for CompiledFunctionBytes<'a>
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for InstantiatedGlobals
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for InstantiatedTable
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for Export
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ExportSection
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for FunctionSection
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for FunctionType
Parse a function type. Since we do not support multiple return values we ensure at parse time that there are no more than one return values.
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for Import
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ImportSection
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for Limits
Parse a limit, and additionally ensure that, if given, the upper bound is no less than lower bound.
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for Local
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for MemArg
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for MemorySection
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for MemoryType
Memory types are just limits on the size of the memory. This also ensures that limits are within range 2^16.
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for TableSection
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for TableType
Parse a table type. In the version we support there is a single table type, the funcref, so this only records the resulting table limits. This instance additionally ensures that the limits are valid, i.e., in range 2^32. Since the bounds are 32-bit integers, this is true by default.
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for TypeSection
impl<'a, Ctx: Copy> Parseable<'a, Ctx> for UnparsedSection<'a>
Parse a section skeleton, which consists of parsing the section ID and recording the boundaries of it.
impl<'a, Ctx: Copy, I: Parseable<'a, Ctx>> Parseable<'a, Ctx> for Artifact<I, CompiledFunctionBytes<'a>>
NB: This implementation is only meant to be used on trusted sources. It optimistically allocates memory, which could lead to problems if the input is untrusted.