Expr
std::meta::expr
contains methods on the built-in Expr
type for quoted, syntactically valid expressions.
Methods
as_array
pub comptime fn as_array(self) -> Option<[Expr]> {}
If this expression is an array, this returns a slice of each element in the array.
as_assert
pub comptime fn as_assert(self) -> Option<(Expr, Option<Expr>)> {}
If this expression is an assert, this returns the assert expression and the optional message.
as_assert_eq
pub comptime fn as_assert_eq(self) -> Option<(Expr, Expr, Option<Expr>)> {}
If this expression is an assert_eq, this returns the left-hand-side and right-hand-side expressions, together with the optional message.
as_assign
pub comptime fn as_assign(self) -> Option<(Expr, Expr)> {}
If this expression is an assignment, this returns a tuple with the left hand side and right hand side in order.
as_binary_op
pub comptime fn as_binary_op(self) -> Option<(Expr, BinaryOp, Expr)> {}
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
pub comptime fn as_block(self) -> Option<[Expr]> {}
If this expression is a block { stmt1; stmt2; ...; stmtN }
, return
a slice containing each statement.
as_bool
pub comptime fn as_bool(self) -> Option<bool> {}
If this expression is a boolean literal, return that literal.
as_cast
#[builtin(expr_as_cast)]
pub comptime fn as_cast(self) -> Option<(Expr, UnresolvedType)> {}
If this expression is a cast expression (expr as type
), returns the casted
expression and the type to cast to.
as_comptime
pub comptime fn as_comptime(self) -> Option<[Expr]> {}
If this expression is a comptime { stmt1; stmt2; ...; stmtN }
block,
return each statement in the block.
as_constructor
pub comptime fn as_constructor(self) -> Option<(UnresolvedType, [(Quoted, Expr)])> {}
If this expression is a constructor Type { field1: expr1, ..., fieldN: exprN }
,
return the type and the fields.
as_for
pub comptime fn as_for(self) -> Option<(Quoted, Expr, Expr)> {}
If this expression is a for statement over a single expression, return the identifier, the expression and the for loop body.
as_for_range
pub comptime fn as_for(self) -> Option<(Quoted, Expr, Expr)> {}
If this expression is a for statement over a range, return the identifier, the range start, the range end and the for loop body.
as_function_call
pub comptime fn as_function_call(self) -> Option<(Expr, [Expr])> {}
If this expression is a function call foo(arg1, ..., argN)
, return
the function and a slice of each argument.
as_if
pub comptime fn as_if(self) -> Option<(Expr, Expr, Option<Expr>)> {}
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
pub comptime fn as_index(self) -> Option<(Expr, Expr)> {}
If this expression is an index into an array array[index]
, return the
array and the index.
as_integer
pub comptime fn as_integer(self) -> Option<(Field, bool)> {}
If this expression is an integer literal, return the integer as a field as well as whether the integer is negative (true) or not (false).