pub struct Expression { /* private fields */ }Expand description
Function bodies, initialization values for globals, and offsets of element or data segments are given as expressions, which are sequences of instructions terminated by an ๐พ๐๐ฝ marker. In some places, validation restricts expressions to be constant, which limits the set of allowable instructions.
See https://webassembly.github.io/spec/core/syntax/instructions.html#expressions
ยงExamples
ยงNon-Empty
use wasm_ast::{Expression, ControlInstruction, NumericInstruction, Instruction};
let expression = Expression::new(vec![0i32.into(), ControlInstruction::Nop.into()]);
assert_eq!(
expression,
Expression::new(vec![
Instruction::Numeric(NumericInstruction::I32Constant(0 as i32)),
Instruction::Control(ControlInstruction::Nop),
])
);
assert_eq!(expression.instructions(), &[
Instruction::Numeric(NumericInstruction::I32Constant(0)),
Instruction::Control(ControlInstruction::Nop),
]);
assert_eq!(expression.len(), 2);
assert!(!expression.is_empty());
assert_eq!(
expression,
vec![
Instruction::Numeric(NumericInstruction::I32Constant(0)),
Instruction::Control(ControlInstruction::Nop),
].into()
);ยงEmpty
use wasm_ast::Expression;
let expression = Expression::new(vec![]);
assert_eq!(expression, Expression::empty());
assert_eq!(expression, vec![].into());
assert_eq!(expression.instructions(), &[]);
assert_eq!(expression.len(), 0);
assert!(expression.is_empty());Implementationsยง
Sourceยงimpl Expression
impl Expression
Sourcepub fn new(instructions: Vec<Instruction>) -> Self
pub fn new(instructions: Vec<Instruction>) -> Self
Create a new expression from the given instructions.
Sourcepub fn instructions(&self) -> &[Instruction]
pub fn instructions(&self) -> &[Instruction]
The instructions for this expression.
Trait Implementationsยง
Sourceยงimpl Clone for Expression
impl Clone for Expression
Sourceยงfn clone(&self) -> Expression
fn clone(&self) -> Expression
Returns a duplicate of the value. Read more
1.0.0 ยท Sourceยงfn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSourceยงimpl Debug for Expression
impl Debug for Expression
Sourceยงimpl From<Vec<Instruction>> for Expression
impl From<Vec<Instruction>> for Expression
Sourceยงfn from(instructions: Vec<Instruction>) -> Self
fn from(instructions: Vec<Instruction>) -> Self
Converts to this type from the input type.
Sourceยงimpl PartialEq for Expression
impl PartialEq for Expression
impl StructuralPartialEq for Expression
Auto Trait Implementationsยง
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more