Skip to main content
Version: dev

Expr

std::meta::expr contains methods on the built-in Expr type for quoted, syntactically valid expressions.

Methods

as_array

as_array
fn as_array(self) -> Option<[Expr]> {}

Source code: noir_stdlib/src/meta/expr.nr#L7-L9

If this expression is an array, this returns a slice of each element in the array.

as_assign

as_assign
fn as_assign(self) -> Option<(Expr, Expr)> {}

Source code: noir_stdlib/src/meta/expr.nr#L12-L14

If this expression is an assignment, this returns a tuple with the left hand side and right hand side in order.

as_binary_op

as_binary_op
fn as_binary_op(self) -> Option<(Expr, BinaryOp, Expr)> {}

Source code: noir_stdlib/src/meta/expr.nr#L22-L24

If this expression is a binary operator operation <lhs> <op> <rhs>, return the left-hand side, operator, and the right-hand side of the operation.

as_block

as_block
fn as_block(self) -> Option<[Expr]> {}

Source code: noir_stdlib/src/meta/expr.nr#L27-L29

If this expression is a block { stmt1; stmt2; ...; stmtN }, return a slice containing each statement.

as_bool

as_bool
fn as_bool(self) -> Option<bool> {}

Source code: noir_stdlib/src/meta/expr.nr#L32-L34

If this expression is a boolean literal, return that literal.

as_comptime

as_comptime
fn as_comptime(self) -> Option<[Expr]> {}

Source code: noir_stdlib/src/meta/expr.nr#L40-L42

If this expression is a comptime { stmt1; stmt2; ...; stmtN } block, return each statement in the block.

as_function_call

as_function_call
fn as_function_call(self) -> Option<(Expr, [Expr])> {}

Source code: noir_stdlib/src/meta/expr.nr#L45-L47

If this expression is a function call foo(arg1, ..., argN), return the function and a slice of each argument.

as_if

as_if
fn as_if(self) -> Option<(Expr, Expr, Option<Expr>)> {}

Source code: noir_stdlib/src/meta/expr.nr#L50-L52

If this expression is an if condition { then_branch } else { else_branch }, return the condition, then branch, and else branch. If there is no else branch, None is returned for that branch instead.

as_index

as_index
fn as_index(self) -> Option<(Expr, Expr)> {}

Source code: noir_stdlib/src/meta/expr.nr#L55-L57

If this expression is an index into an array array[index], return the array and the index.

as_integer

as_integer
fn as_integer(self) -> Option<(Field, bool)> {}

Source code: noir_stdlib/src/meta/expr.nr#L17-L19

If this element is an integer literal, return the integer as a field as well as whether the integer is negative (true) or not (false).

as_member_access

as_member_access
fn as_member_access(self) -> Option<(Expr, Quoted)> {}

Source code: noir_stdlib/src/meta/expr.nr#L60-L62

If this expression is a member access foo.bar, return the struct/tuple expression and the field. The field will be represented as a quoted value.

as_method_call

as_method_call
fn as_method_call(self) -> Option<(Expr, Quoted, [UnresolvedType], [Expr])> {}

Source code: noir_stdlib/src/meta/expr.nr#L65-L67

If this expression is a method call foo.bar::<generic1, ..., genericM>(arg1, ..., argN), return the receiver, method name, a slice of each generic argument, and a slice of each argument.

as_repeated_element_array

as_repeated_element_array
fn as_repeated_element_array(self) -> Option<(Expr, Expr)> {}

Source code: noir_stdlib/src/meta/expr.nr#L70-L72

If this expression is a repeated element array [elem; length], return the repeated element and the length expressions.

as_repeated_element_slice

as_repeated_element_slice
fn as_repeated_element_slice(self) -> Option<(Expr, Expr)> {}

Source code: noir_stdlib/src/meta/expr.nr#L75-L77

If this expression is a repeated element slice [elem; length], return the repeated element and the length expressions.

as_slice

as_slice
fn as_slice(self) -> Option<[Expr]> {}

Source code: noir_stdlib/src/meta/expr.nr#L80-L82

If this expression is a slice literal &[elem1, ..., elemN], return each element of the slice.

as_tuple

as_tuple
fn as_tuple(self) -> Option<[Expr]> {}

Source code: noir_stdlib/src/meta/expr.nr#L85-L87

If this expression is a tuple (field1, ..., fieldN), return each element of the tuple.

as_unary_op

as_unary_op
fn as_unary_op(self) -> Option<(UnaryOp, Expr)> {}

Source code: noir_stdlib/src/meta/expr.nr#L90-L92

If this expression is a unary operation <op> <rhs>, return the unary operator as well as the right-hand side expression.

as_unsafe

as_unsafe
fn as_unsafe(self) -> Option<[Expr]> {}

Source code: noir_stdlib/src/meta/expr.nr#L95-L97

If this expression is an unsafe { stmt1; ...; stmtN } block, return each statement inside in a slice.

has_semicolon

has_semicolon
fn has_semicolon(self) -> bool {}

Source code: noir_stdlib/src/meta/expr.nr#L100-L102

true if this expression is trailed by a semicolon. E.g.

comptime {
let expr1 = quote { 1 + 2 }.as_expr().unwrap();
let expr2 = quote { 1 + 2; }.as_expr().unwrap();

assert(expr1.as_binary_op().is_some());
assert(expr2.as_binary_op().is_some());

assert(!expr1.has_semicolon());
assert(expr2.has_semicolon());
}

is_break

is_break
fn is_break(self) -> bool {}

Source code: noir_stdlib/src/meta/expr.nr#L105-L107

true if this expression is break.

is_continue

is_continue
fn is_continue(self) -> bool {}

Source code: noir_stdlib/src/meta/expr.nr#L110-L112

true if this expression is continue.