Trait Parseable

Source
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§

Source

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.

Source§

fn parse(ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>

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.

Source§

fn parse(ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>

Source§

impl<'a, Ctx> Parseable<'a, Ctx> for i32

Implementation for i32 according to the Wasm specification.

Source§

fn parse(_ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>

Source§

impl<'a, Ctx> Parseable<'a, Ctx> for i64

Implementation for i64 according to the Wasm specification.

Source§

fn parse(_ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>

Source§

impl<'a, Ctx> Parseable<'a, Ctx> for u16

Implementation for u16 according to the Wasm specification.

Source§

fn parse(_ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>

Source§

impl<'a, Ctx> Parseable<'a, Ctx> for u32

Implementation for u32 according to the Wasm specification.

Source§

fn parse(_ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>

Source§

impl<'a, Ctx> Parseable<'a, Ctx> for u64

Implementation for u64 according to the Wasm specification.

Source§

fn parse(_ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>

Source§

impl<'a, Ctx, X: Parseable<'a, Ctx>> Parseable<'a, Ctx> for Rc<X>

Source§

fn parse(ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>

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.

Source§

fn parse(ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>

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.

Source§

fn parse(ctx: Ctx, cursor: &mut Cursor<&'a [u8]>) -> ParseResult<Self>

Implementors§

Source§

impl<'a> Parseable<'a, ValidationConfig> for Global

Source§

impl<'a> Parseable<'a, ValidationConfig> for GlobalSection

Source§

impl<'a, Ctx> Parseable<'a, Ctx> for ArtifactVersion

Source§

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.

Source§

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.

Source§

impl<'a, Ctx> Parseable<'a, Ctx> for SectionId

Parsing of the section ID according to the linked Wasm specification.

Source§

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.

Source§

impl<'a, Ctx> Parseable<'a, Ctx> for StartSection

Source§

impl<'a, Ctx> Parseable<'a, Ctx> for Byte

Parse a single byte.

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ExportDescription

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ImportDescription

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ArtifactData

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ArtifactLocal

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ArtifactMemory

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ArtifactNamedImport

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for CompiledFunctionBytes<'a>

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for InstantiatedGlobals

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for InstantiatedTable

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for Export

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ExportSection

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for FunctionSection

Source§

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.

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for Import

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for ImportSection

Source§

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.

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for Local

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for MemArg

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for MemorySection

Source§

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.

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for TableSection

Source§

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.

Source§

impl<'a, Ctx: Copy> Parseable<'a, Ctx> for TypeSection

Source§

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.

Source§

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.