[−][src]Enum syn::Expr
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
.
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
Box(ExprBox)
A box expression: box f
.
This type is available if Syn is built with the "full"
feature.
InPlace(ExprInPlace)
A placement expression: place <- value
.
This type is available if Syn is built with the "full"
feature.
Array(ExprArray)
A slice literal expression: [a, b, c, d]
.
This type is available if Syn is built with the "full"
feature.
Call(ExprCall)
A function call expression: invoke(a, b)
.
This type is available if Syn is built with the "derive"
or
"full"
feature.
MethodCall(ExprMethodCall)
A method call expression: x.foo::<T>(a, b)
.
This type is available if Syn is built with the "full"
feature.
Tuple(ExprTuple)
A tuple expression: (a, b, c, d)
.
This type is available if Syn is built with the "full"
feature.
Binary(ExprBinary)
A binary operation: a + b
, a * b
.
This type is available if Syn is built with the "derive"
or
"full"
feature.
Unary(ExprUnary)
A unary operation: !x
, *x
.
This type is available if Syn is built with the "derive"
or
"full"
feature.
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.
Cast(ExprCast)
A cast expression: foo as f64
.
This type is available if Syn is built with the "derive"
or
"full"
feature.
Type(ExprType)
A type ascription expression: foo: f64
.
This type is available if Syn is built with the "full"
feature.
Let(ExprLet)
A let
guard: let Some(x) = opt
.
This type is available if Syn is built with the "full"
feature.
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.
While(ExprWhile)
A while loop: while expr { ... }
.
This type is available if Syn is built with the "full"
feature.
ForLoop(ExprForLoop)
A for loop: for pat in expr { ... }
.
This type is available if Syn is built with the "full"
feature.
Loop(ExprLoop)
Conditionless loop: loop { ... }
.
This type is available if Syn is built with the "full"
feature.
Match(ExprMatch)
A match
expression: match n { Some(n) => {}, None => {} }
.
This type is available if Syn is built with the "full"
feature.
Closure(ExprClosure)
A closure expression: |a, b| a + b
.
This type is available if Syn is built with the "full"
feature.
Unsafe(ExprUnsafe)
An unsafe block: unsafe { ... }
.
This type is available if Syn is built with the "full"
feature.
Block(ExprBlock)
A blocked scope: { ... }
.
This type is available if Syn is built with the "full"
feature.
Assign(ExprAssign)
An assignment expression: a = compute()
.
This type is available if Syn is built with the "full"
feature.
AssignOp(ExprAssignOp)
A compound assignment expression: counter += 1
.
This type is available if Syn is built with the "full"
feature.
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.
Index(ExprIndex)
A square bracketed indexing expression: vector[2]
.
This type is available if Syn is built with the "derive"
or
"full"
feature.
Range(ExprRange)
A range expression: 1..2
, 1..
, ..2
, 1..=2
, ..=2
.
This type is available if Syn is built with the "full"
feature.
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.
Reference(ExprReference)
A referencing operation: &a
or &mut a
.
This type is available if Syn is built with the "full"
feature.
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.
Continue(ExprContinue)
A continue
, with an optional label.
This type is available if Syn is built with the "full"
feature.
Return(ExprReturn)
A return
, with an optional value to be returned.
This type is available if Syn is built with the "full"
feature.
Macro(ExprMacro)
A macro invocation expression: format!("{}", q)
.
This type is available if Syn is built with the "full"
feature.
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.
Repeat(ExprRepeat)
An array literal constructed from one repeated element: [0u8; N]
.
This type is available if Syn is built with the "full"
feature.
Paren(ExprParen)
A parenthesized expression: (a + b)
.
This type is available if Syn is built with the "full"
feature.
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.
Try(ExprTry)
A try-expression: expr?
.
This type is available if Syn is built with the "full"
feature.
Async(ExprAsync)
An async block: async { ... }
.
This type is available if Syn is built with the "full"
feature.
TryBlock(ExprTryBlock)
A try block: try { ... }
.
This type is available if Syn is built with the "full"
feature.
Yield(ExprYield)
A yield expression: yield expr
.
This type is available if Syn is built with the "full"
feature.
Verbatim(ExprVerbatim)
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 Parse for Expr
[src]
impl Parse for Expr
fn parse(input: ParseStream) -> Result<Self>
[src]
fn parse(input: ParseStream) -> Result<Self>
impl PartialEq<Expr> for Expr
[src]
impl PartialEq<Expr> for Expr
impl Clone for Expr
[src]
impl Clone for Expr
fn clone(&self) -> Expr
[src]
fn clone(&self) -> Expr
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl From<ExprBox> for Expr
[src]
impl From<ExprBox> for Expr
impl From<ExprInPlace> for Expr
[src]
impl From<ExprInPlace> for Expr
fn from(e: ExprInPlace) -> Expr
[src]
fn from(e: ExprInPlace) -> Expr
impl From<ExprArray> for Expr
[src]
impl From<ExprArray> for Expr
impl From<ExprCall> for Expr
[src]
impl From<ExprCall> for Expr
impl From<ExprMethodCall> for Expr
[src]
impl From<ExprMethodCall> for Expr
fn from(e: ExprMethodCall) -> Expr
[src]
fn from(e: ExprMethodCall) -> Expr
impl From<ExprTuple> for Expr
[src]
impl From<ExprTuple> for Expr
impl From<ExprBinary> for Expr
[src]
impl From<ExprBinary> for Expr
fn from(e: ExprBinary) -> Expr
[src]
fn from(e: ExprBinary) -> Expr
impl From<ExprUnary> for Expr
[src]
impl From<ExprUnary> for Expr
impl From<ExprLit> for Expr
[src]
impl From<ExprLit> for Expr
impl From<ExprCast> for Expr
[src]
impl From<ExprCast> for Expr
impl From<ExprType> for Expr
[src]
impl From<ExprType> for Expr
impl From<ExprLet> for Expr
[src]
impl From<ExprLet> for Expr
impl From<ExprIf> for Expr
[src]
impl From<ExprIf> for Expr
impl From<ExprWhile> for Expr
[src]
impl From<ExprWhile> for Expr
impl From<ExprForLoop> for Expr
[src]
impl From<ExprForLoop> for Expr
fn from(e: ExprForLoop) -> Expr
[src]
fn from(e: ExprForLoop) -> Expr
impl From<ExprLoop> for Expr
[src]
impl From<ExprLoop> for Expr
impl From<ExprMatch> for Expr
[src]
impl From<ExprMatch> for Expr
impl From<ExprClosure> for Expr
[src]
impl From<ExprClosure> for Expr
fn from(e: ExprClosure) -> Expr
[src]
fn from(e: ExprClosure) -> Expr
impl From<ExprUnsafe> for Expr
[src]
impl From<ExprUnsafe> for Expr
fn from(e: ExprUnsafe) -> Expr
[src]
fn from(e: ExprUnsafe) -> Expr
impl From<ExprBlock> for Expr
[src]
impl From<ExprBlock> for Expr
impl From<ExprAssign> for Expr
[src]
impl From<ExprAssign> for Expr
fn from(e: ExprAssign) -> Expr
[src]
fn from(e: ExprAssign) -> Expr
impl From<ExprAssignOp> for Expr
[src]
impl From<ExprAssignOp> for Expr
fn from(e: ExprAssignOp) -> Expr
[src]
fn from(e: ExprAssignOp) -> Expr
impl From<ExprField> for Expr
[src]
impl From<ExprField> for Expr
impl From<ExprIndex> for Expr
[src]
impl From<ExprIndex> for Expr
impl From<ExprRange> for Expr
[src]
impl From<ExprRange> for Expr
impl From<ExprPath> for Expr
[src]
impl From<ExprPath> for Expr
impl From<ExprReference> for Expr
[src]
impl From<ExprReference> for Expr
fn from(e: ExprReference) -> Expr
[src]
fn from(e: ExprReference) -> Expr
impl From<ExprBreak> for Expr
[src]
impl From<ExprBreak> for Expr
impl From<ExprContinue> for Expr
[src]
impl From<ExprContinue> for Expr
fn from(e: ExprContinue) -> Expr
[src]
fn from(e: ExprContinue) -> Expr
impl From<ExprReturn> for Expr
[src]
impl From<ExprReturn> for Expr
fn from(e: ExprReturn) -> Expr
[src]
fn from(e: ExprReturn) -> Expr
impl From<ExprMacro> for Expr
[src]
impl From<ExprMacro> for Expr
impl From<ExprStruct> for Expr
[src]
impl From<ExprStruct> for Expr
fn from(e: ExprStruct) -> Expr
[src]
fn from(e: ExprStruct) -> Expr
impl From<ExprRepeat> for Expr
[src]
impl From<ExprRepeat> for Expr
fn from(e: ExprRepeat) -> Expr
[src]
fn from(e: ExprRepeat) -> Expr
impl From<ExprParen> for Expr
[src]
impl From<ExprParen> for Expr
impl From<ExprGroup> for Expr
[src]
impl From<ExprGroup> for Expr
impl From<ExprTry> for Expr
[src]
impl From<ExprTry> for Expr
impl From<ExprAsync> for Expr
[src]
impl From<ExprAsync> for Expr
impl From<ExprTryBlock> for Expr
[src]
impl From<ExprTryBlock> for Expr
fn from(e: ExprTryBlock) -> Expr
[src]
fn from(e: ExprTryBlock) -> Expr
impl From<ExprYield> for Expr
[src]
impl From<ExprYield> for Expr
impl From<ExprVerbatim> for Expr
[src]
impl From<ExprVerbatim> for Expr
fn from(e: ExprVerbatim) -> Expr
[src]
fn from(e: ExprVerbatim) -> Expr
impl Eq for Expr
[src]
impl Eq for Expr
impl Hash for Expr
[src]
impl Hash for Expr
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Debug for Expr
[src]
impl Debug for Expr
impl ToTokens for Expr
[src]
impl ToTokens for Expr
fn to_tokens(&self, tokens: &mut TokenStream)
[src]
fn to_tokens(&self, tokens: &mut TokenStream)
fn into_token_stream(self) -> TokenStream
[src]
fn into_token_stream(self) -> TokenStream
Convert self
directly into a TokenStream
object. Read more
Auto Trait Implementations
Blanket Implementations
impl<T> Spanned for T where
T: ToTokens,
[src]
impl<T> Spanned for T where
T: ToTokens,
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,