[][src]Enum syn::Expr

pub enum Expr {
    Box(ExprBox),
    InPlace(ExprInPlace),
    Array(ExprArray),
    Call(ExprCall),
    MethodCall(ExprMethodCall),
    Tuple(ExprTuple),
    Binary(ExprBinary),
    Unary(ExprUnary),
    Lit(ExprLit),
    Cast(ExprCast),
    Type(ExprType),
    If(ExprIf),
    IfLet(ExprIfLet),
    While(ExprWhile),
    WhileLet(ExprWhileLet),
    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),
    Catch(ExprCatch),
    Yield(ExprYield),
    Verbatim(ExprVerbatim),
}

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::IfLet(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 IfLet case we get to use expr.pat, expr.then_branch, expr.else_branch.

The pattern is similar if the input expression is borrowed:

match *expr {
    Expr::MethodCall(ref expr) => {

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

Expr::MethodCall(ExprMethodCall { method, args, .. }) => { // repetitive

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(ref 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

A box expression: box f.

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

A placement expression: place <- value.

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

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

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

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

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

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

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

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

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

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

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

A unary operation: !x, *x.

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

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

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

A cast expression: foo as f64.

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

A type ascription expression: foo: f64.

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

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

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

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

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

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

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

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

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

A while-let loop: while let pat = expr { ... }.

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

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

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

Conditionless loop: loop { ... }.

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

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

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

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

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

An unsafe block: unsafe { ... }.

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

A blocked scope: { ... }.

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

An assignment expression: a = compute().

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

A compound assignment expression: counter += 1.

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

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.

A square bracketed indexing expression: vector[2].

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

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

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

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.

A referencing operation: &a or &mut a.

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

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

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

A continue, with an optional label.

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

A return, with an optional value to be returned.

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

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

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

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.

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

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

A parenthesized expression: (a + b).

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

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.

A try-expression: expr?.

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

A catch expression: do catch { ... }.

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

A yield expression: yield expr.

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

Tokens in expression position not interpreted by Syn.

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

Trait Implementations

impl Synom for Expr
[src]

A short name of the type being parsed. Read more

impl Debug for Expr
[src]

Formats the value using the given formatter. Read more

impl Eq for Expr
[src]

impl PartialEq for Expr
[src]

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

This method tests for !=.

impl Hash for Expr
[src]

Feeds this value into the given [Hasher]. Read more

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

impl Clone for Expr
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl From<ExprBox> for Expr
[src]

Performs the conversion.

impl From<ExprInPlace> for Expr
[src]

Performs the conversion.

impl From<ExprArray> for Expr
[src]

Performs the conversion.

impl From<ExprCall> for Expr
[src]

Performs the conversion.

impl From<ExprMethodCall> for Expr
[src]

Performs the conversion.

impl From<ExprTuple> for Expr
[src]

Performs the conversion.

impl From<ExprBinary> for Expr
[src]

Performs the conversion.

impl From<ExprUnary> for Expr
[src]

Performs the conversion.

impl From<ExprLit> for Expr
[src]

Performs the conversion.

impl From<ExprCast> for Expr
[src]

Performs the conversion.

impl From<ExprType> for Expr
[src]

Performs the conversion.

impl From<ExprIf> for Expr
[src]

Performs the conversion.

impl From<ExprIfLet> for Expr
[src]

Performs the conversion.

impl From<ExprWhile> for Expr
[src]

Performs the conversion.

impl From<ExprWhileLet> for Expr
[src]

Performs the conversion.

impl From<ExprForLoop> for Expr
[src]

Performs the conversion.

impl From<ExprLoop> for Expr
[src]

Performs the conversion.

impl From<ExprMatch> for Expr
[src]

Performs the conversion.

impl From<ExprClosure> for Expr
[src]

Performs the conversion.

impl From<ExprUnsafe> for Expr
[src]

Performs the conversion.

impl From<ExprBlock> for Expr
[src]

Performs the conversion.

impl From<ExprAssign> for Expr
[src]

Performs the conversion.

impl From<ExprAssignOp> for Expr
[src]

Performs the conversion.

impl From<ExprField> for Expr
[src]

Performs the conversion.

impl From<ExprIndex> for Expr
[src]

Performs the conversion.

impl From<ExprRange> for Expr
[src]

Performs the conversion.

impl From<ExprPath> for Expr
[src]

Performs the conversion.

impl From<ExprReference> for Expr
[src]

Performs the conversion.

impl From<ExprBreak> for Expr
[src]

Performs the conversion.

impl From<ExprContinue> for Expr
[src]

Performs the conversion.

impl From<ExprReturn> for Expr
[src]

Performs the conversion.

impl From<ExprMacro> for Expr
[src]

Performs the conversion.

impl From<ExprStruct> for Expr
[src]

Performs the conversion.

impl From<ExprRepeat> for Expr
[src]

Performs the conversion.

impl From<ExprParen> for Expr
[src]

Performs the conversion.

impl From<ExprGroup> for Expr
[src]

Performs the conversion.

impl From<ExprTry> for Expr
[src]

Performs the conversion.

impl From<ExprCatch> for Expr
[src]

Performs the conversion.

impl From<ExprYield> for Expr
[src]

Performs the conversion.

impl From<ExprVerbatim> for Expr
[src]

Performs the conversion.

impl ToTokens for Expr
[src]

Write self to the given TokenStream. Read more

Convert self directly into a TokenStream object. Read more

Auto Trait Implementations

impl !Send for Expr

impl !Sync for Expr

Blanket Implementations

impl<T> Spanned for T where
    T: ToTokens
[src]

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

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

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

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Important traits for &'a mut W

Immutably borrows from an owned value. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Important traits for &'a mut W

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<E> SpecializationError for E
[src]

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

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

Create an error for a missing method specialization. Defaults to panicking with type, trait & method names. S is the encoder/decoder state type, T is the type being encoded/decoded, and the arguments are the names of the trait and method that should've been overridden. Read more

impl<T> Erased for T
[src]

impl<T> Send for T where
    T: ?Sized
[src]

impl<T> Sync for T where
    T: ?Sized
[src]

impl<T> Erased for T