pub enum PureExpr {
Show 32 variants
Lit(String),
Path(String),
Binary {
op: String,
left: Box<PureExpr>,
right: Box<PureExpr>,
},
Unary {
op: String,
expr: Box<PureExpr>,
},
Call {
func: Box<PureExpr>,
args: Vec<PureExpr>,
},
MethodCall {
receiver: Box<PureExpr>,
method: String,
turbofish: Option<String>,
args: Vec<PureExpr>,
},
Field {
expr: Box<PureExpr>,
field: String,
},
Index {
expr: Box<PureExpr>,
index: Box<PureExpr>,
},
Block {
label: Option<String>,
block: PureBlock,
},
If {
cond: Box<PureExpr>,
then_branch: PureBlock,
else_branch: Option<Box<PureExpr>>,
},
Match {
expr: Box<PureExpr>,
arms: Vec<PureMatchArm>,
},
Loop {
label: Option<String>,
body: PureBlock,
},
While {
label: Option<String>,
cond: Box<PureExpr>,
body: PureBlock,
},
For {
label: Option<String>,
pat: PurePattern,
expr: Box<PureExpr>,
body: PureBlock,
},
Return(Option<Box<PureExpr>>),
Break {
label: Option<String>,
expr: Option<Box<PureExpr>>,
},
Continue {
label: Option<String>,
},
Closure {
is_async: bool,
is_move: bool,
params: Vec<PureClosureParam>,
ret: Option<PureType>,
body: Box<PureExpr>,
},
Struct {
path: String,
fields: Vec<(String, PureExpr)>,
},
Tuple(Vec<PureExpr>),
Array(Vec<PureExpr>),
Ref {
is_mut: bool,
expr: Box<PureExpr>,
},
Macro {
name: String,
delimiter: MacroDelimiter,
tokens: String,
},
Await(Box<PureExpr>),
Try(Box<PureExpr>),
Range {
start: Option<Box<PureExpr>>,
end: Option<Box<PureExpr>>,
inclusive: bool,
},
Cast {
expr: Box<PureExpr>,
ty: PureType,
},
Let {
pattern: PurePattern,
expr: Box<PureExpr>,
},
Async {
is_move: bool,
body: PureBlock,
},
Unsafe(PureBlock),
Repeat {
expr: Box<PureExpr>,
len: Box<PureExpr>,
},
Other(String),
}Expand description
An expression.
Variants§
Lit(String)
Literal: 1, "hello", true
Path(String)
Path: x, std::io::stdin
Binary
Binary operation: a + b
Fields
Unary
Unary operation: -x, !x, *x, &x
Call
Function call: foo(a, b)
MethodCall
Method call: x.foo(a, b) or x.foo::<T>(a, b)
Fields
Field
Field access: x.field
Index
Index: x[i]
Block
Block: { ... } or 'label: { ... }
If
If: if cond { ... } else { ... }
Fields
Match
Match: match x { ... }
Loop
Loop: loop { ... } or 'label: loop { ... }
While
While: while cond { ... } or 'label: while cond { ... }
Fields
For
For: for pat in expr { ... } or 'label: for pat in expr { ... }
Fields
pat: PurePatternIteration binding pattern.
Return(Option<Box<PureExpr>>)
Return: return x
Break
Break: break x or break 'label x
Fields
Continue
Continue: continue or continue 'label
Closure
Closure: |x| x + 1, |x: Foo| -> Bar { x }, move |x| x
Fields
params: Vec<PureClosureParam>Parameters with optional type annotations.
Struct
Struct literal: Point { x: 1, y: 2 }
Fields
Tuple(Vec<PureExpr>)
Tuple: (a, b, c)
Array(Vec<PureExpr>)
Array: [1, 2, 3]
Ref
Reference: &x, &mut x
Macro
Macro invocation: println!(...)
Fields
delimiter: MacroDelimiterDelimiter style around tokens.
Await(Box<PureExpr>)
Await: x.await
Try(Box<PureExpr>)
Try: x?
Range
Range: a..b, ..b, a.., .., a..=b
Fields
Cast
Cast: x as T
Let
Let expression (in conditions): let Some(x) = y
Fields
pattern: PurePatternPattern on the LHS of let.
Async
Async block: async { ... } or async move { ... }
Unsafe(PureBlock)
Unsafe block: unsafe { ... }
Repeat
Array repeat: [expr; N]
Other(String)
Other (as string).
Implementations§
Source§impl PureExpr
impl PureExpr
Sourcepub fn method_call(
receiver: Box<PureExpr>,
method: String,
args: Vec<PureExpr>,
) -> Self
pub fn method_call( receiver: Box<PureExpr>, method: String, args: Vec<PureExpr>, ) -> Self
Create a MethodCall with default turbofish (None)
Sourcepub fn closure(params: Vec<PureClosureParam>, body: Box<PureExpr>) -> Self
pub fn closure(params: Vec<PureClosureParam>, body: Box<PureExpr>) -> Self
Create a Closure with untyped params and no return type annotation.
Sourcepub fn get_child(&self, index: usize) -> Option<&PureExpr>
pub fn get_child(&self, index: usize) -> Option<&PureExpr>
Get child expression at index.
Index mapping varies by variant:
Binary: 0=left, 1=rightUnary,Field,Ref,Await,Try,Cast,Let: 0=exprCall: 0=func, 1..=argsMethodCall: 0=receiver, 1..=argsIndex,Repeat: 0=expr, 1=index/lenRange: 0=start, 1=end (if present)If: 0=cond, 1=else_branch (if present)While,For: 0=cond/exprMatch: 0=exprReturn,Break: 0=inner (if present)Closure: 0=bodyTuple,Array: 0..n=elementsStruct: 0..n=field values- Others: None
Sourcepub fn get_child_mut(&mut self, index: usize) -> Option<&mut PureExpr>
pub fn get_child_mut(&mut self, index: usize) -> Option<&mut PureExpr>
Get mutable child expression at index.
Sourcepub fn get_block(&self) -> Option<&PureBlock>
pub fn get_block(&self) -> Option<&PureBlock>
Get the contained block (for Block, Loop, Async, Unsafe, If, While, For).
Sourcepub fn get_block_mut(&mut self) -> Option<&mut PureBlock>
pub fn get_block_mut(&mut self) -> Option<&mut PureBlock>
Get mutable contained block.
Sourcepub fn child_count(&self) -> usize
pub fn child_count(&self) -> usize
Number of direct child expressions.
Navigate to a nested expression mutably.