Enum devise::syn::Expr[][src]

pub enum Expr {
Show 40 variants Box(ExprBox), InPlace(ExprInPlace), Array(ExprArray), Call(ExprCall), MethodCall(ExprMethodCall), Tuple(ExprTuple), Binary(ExprBinary), Unary(ExprUnary), Lit(ExprLit), Cast(ExprCast), Type(ExprType), Let(ExprLet), If(ExprIf), While(ExprWhile), ForLoop(ExprForLoop), Loop(ExprLoop), Match(ExprMatch), Closure(ExprClosure), Unsafe(ExprUnsafe), Block(ExprBlock), Assign(ExprAssign), AssignOp(ExprAssignOp), Field(ExprField), Index(ExprIndex), Range(ExprRange), Path(ExprPath), Reference(ExprReference), Break(ExprBreak), Continue(ExprContinue), Return(ExprReturn), Macro(ExprMacro), Struct(ExprStruct), Repeat(ExprRepeat), Paren(ExprParen), Group(ExprGroup), Try(ExprTry), Async(ExprAsync), TryBlock(ExprTryBlock), Yield(ExprYield), Verbatim(ExprVerbatim),
}
Expand description

A Rust expression.

This type is available if Syn is built with the "derive" or "full" feature.

Syntax tree enums

This type is a syntax tree enum. In Syn this and other syntax tree enums are designed to be traversed using the following rebinding idiom.

let expr: Expr = /* ... */;
match expr {
    Expr::MethodCall(expr) => {
        /* ... */
    }
    Expr::Cast(expr) => {
        /* ... */
    }
    Expr::If(expr) => {
        /* ... */
    }

    /* ... */

We begin with a variable expr of type Expr that has no fields (because it is an enum), and by matching on it and rebinding a variable with the same name expr we effectively imbue our variable with all of the data fields provided by the variant that it turned out to be. So for example above if we ended up in the MethodCall case then we get to use expr.receiver, expr.args etc; if we ended up in the If case we get to use expr.cond, expr.then_branch, expr.else_branch.

This approach avoids repeating the variant names twice on every line.

// Repetitive; recommend not doing this.
match expr {
    Expr::MethodCall(ExprMethodCall { method, args, .. }) => {

In general, the name to which a syntax tree enum variant is bound should be a suitable name for the complete syntax tree enum type.

// Binding is called `base` which is the name I would use if I were
// assigning `*discriminant.base` without an `if let`.
if let Expr::Tuple(base) = *discriminant.base {

A sign that you may not be choosing the right variable names is if you see names getting repeated in your code, like accessing receiver.receiver or pat.pat or cond.cond.

Variants

Box(ExprBox)

A box expression: box f.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Box

0: ExprBox
InPlace(ExprInPlace)

A placement expression: place <- value.

This type is available if Syn is built with the "full" feature.

Tuple Fields of InPlace

0: ExprInPlace
Array(ExprArray)

A slice literal expression: [a, b, c, d].

This type is available if Syn is built with the "full" feature.

Tuple Fields of Array

0: ExprArray
Call(ExprCall)

A function call expression: invoke(a, b).

This type is available if Syn is built with the "derive" or "full" feature.

Tuple Fields of Call

0: ExprCall
MethodCall(ExprMethodCall)

A method call expression: x.foo::<T>(a, b).

This type is available if Syn is built with the "full" feature.

Tuple Fields of MethodCall

0: ExprMethodCall
Tuple(ExprTuple)

A tuple expression: (a, b, c, d).

This type is available if Syn is built with the "full" feature.

Tuple Fields of Tuple

0: ExprTuple
Binary(ExprBinary)

A binary operation: a + b, a * b.

This type is available if Syn is built with the "derive" or "full" feature.

Tuple Fields of Binary

0: ExprBinary
Unary(ExprUnary)

A unary operation: !x, *x.

This type is available if Syn is built with the "derive" or "full" feature.

Tuple Fields of Unary

0: ExprUnary
Lit(ExprLit)

A literal in place of an expression: 1, "foo".

This type is available if Syn is built with the "derive" or "full" feature.

Tuple Fields of Lit

0: ExprLit
Cast(ExprCast)

A cast expression: foo as f64.

This type is available if Syn is built with the "derive" or "full" feature.

Tuple Fields of Cast

0: ExprCast
Type(ExprType)

A type ascription expression: foo: f64.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Type

0: ExprType
Let(ExprLet)

A let guard: let Some(x) = opt.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Let

0: ExprLet
If(ExprIf)

An if expression with an optional else block: if expr { ... } else { ... }.

The else branch expression may only be an If or Block expression, not any of the other types of expression.

This type is available if Syn is built with the "full" feature.

Tuple Fields of If

0: ExprIf
While(ExprWhile)

A while loop: while expr { ... }.

This type is available if Syn is built with the "full" feature.

Tuple Fields of While

0: ExprWhile
ForLoop(ExprForLoop)

A for loop: for pat in expr { ... }.

This type is available if Syn is built with the "full" feature.

Tuple Fields of ForLoop

0: ExprForLoop
Loop(ExprLoop)

Conditionless loop: loop { ... }.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Loop

0: ExprLoop
Match(ExprMatch)

A match expression: match n { Some(n) => {}, None => {} }.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Match

0: ExprMatch
Closure(ExprClosure)

A closure expression: |a, b| a + b.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Closure

0: ExprClosure
Unsafe(ExprUnsafe)

An unsafe block: unsafe { ... }.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Unsafe

0: ExprUnsafe
Block(ExprBlock)

A blocked scope: { ... }.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Block

0: ExprBlock
Assign(ExprAssign)

An assignment expression: a = compute().

This type is available if Syn is built with the "full" feature.

Tuple Fields of Assign

0: ExprAssign
AssignOp(ExprAssignOp)

A compound assignment expression: counter += 1.

This type is available if Syn is built with the "full" feature.

Tuple Fields of AssignOp

0: ExprAssignOp
Field(ExprField)

Access of a named struct field (obj.k) or unnamed tuple struct field (obj.0).

This type is available if Syn is built with the "full" feature.

Tuple Fields of Field

0: ExprField
Index(ExprIndex)

A square bracketed indexing expression: vector[2].

This type is available if Syn is built with the "derive" or "full" feature.

Tuple Fields of Index

0: ExprIndex
Range(ExprRange)

A range expression: 1..2, 1.., ..2, 1..=2, ..=2.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Range

0: ExprRange
Path(ExprPath)

A path like std::mem::replace possibly containing generic parameters and a qualified self-type.

A plain identifier like x is a path of length 1.

This type is available if Syn is built with the "derive" or "full" feature.

Tuple Fields of Path

0: ExprPath
Reference(ExprReference)

A referencing operation: &a or &mut a.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Reference

0: ExprReference
Break(ExprBreak)

A break, with an optional label to break and an optional expression.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Break

0: ExprBreak
Continue(ExprContinue)

A continue, with an optional label.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Continue

0: ExprContinue
Return(ExprReturn)

A return, with an optional value to be returned.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Return

0: ExprReturn
Macro(ExprMacro)

A macro invocation expression: format!("{}", q).

This type is available if Syn is built with the "full" feature.

Tuple Fields of Macro

0: ExprMacro
Struct(ExprStruct)

A struct literal expression: Point { x: 1, y: 1 }.

The rest provides the value of the remaining fields as in S { a: 1, b: 1, ..rest }.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Struct

0: ExprStruct
Repeat(ExprRepeat)

An array literal constructed from one repeated element: [0u8; N].

This type is available if Syn is built with the "full" feature.

Tuple Fields of Repeat

0: ExprRepeat
Paren(ExprParen)

A parenthesized expression: (a + b).

This type is available if Syn is built with the "full" feature.

Tuple Fields of Paren

0: ExprParen
Group(ExprGroup)

An expression contained within invisible delimiters.

This variant is important for faithfully representing the precedence of expressions and is related to None-delimited spans in a TokenStream.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Group

0: ExprGroup
Try(ExprTry)

A try-expression: expr?.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Try

0: ExprTry
Async(ExprAsync)

An async block: async { ... }.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Async

0: ExprAsync
TryBlock(ExprTryBlock)

A try block: try { ... }.

This type is available if Syn is built with the "full" feature.

Tuple Fields of TryBlock

0: ExprTryBlock
Yield(ExprYield)

A yield expression: yield expr.

This type is available if Syn is built with the "full" feature.

Tuple Fields of Yield

0: ExprYield
Verbatim(ExprVerbatim)

Tokens in expression position not interpreted by Syn.

This type is available if Syn is built with the "derive" or "full" feature.

Tuple Fields of Verbatim

0: ExprVerbatim

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Write self to the given TokenStream. Read more

Convert self directly into a TokenStream object. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Returns a Span covering the complete contents of this syntax tree node, or Span::call_site() if this node is empty. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.