pub enum Expr {
Show 51 variants
Literal(Literal),
Ident(Ident),
Path(Path),
Macro {
name: Path,
args: Vec<Self>,
span: Span,
},
Binary {
op: BinOp,
left: Box<Self>,
right: Box<Self>,
span: Span,
},
Unary {
op: UnOp,
expr: Box<Self>,
span: Span,
},
Call {
func: Box<Self>,
args: Vec<Self>,
span: Span,
},
MethodCall {
receiver: Box<Self>,
method: Ident,
args: Vec<Self>,
span: Span,
},
Field {
expr: Box<Self>,
field: Ident,
span: Span,
},
Index {
expr: Box<Self>,
index: Box<Self>,
span: Span,
},
MultiDimIndex {
expr: Box<Self>,
indices: Vec<IndexComponent>,
span: Span,
},
Range {
start: Option<Box<Self>>,
end: Option<Box<Self>>,
inclusive: bool,
span: Span,
},
Tuple {
elements: Vec<Self>,
span: Span,
},
Array {
elements: Vec<Self>,
span: Span,
},
ArrayRepeat {
element: Box<Self>,
count: Box<Self>,
span: Span,
},
Struct {
path: Path,
fields: Vec<FieldInit>,
span: Span,
},
Block(Block),
If {
condition: Box<Self>,
then_block: Block,
else_block: Option<Box<Self>>,
span: Span,
},
Match {
expr: Box<Self>,
arms: Vec<MatchArm>,
span: Span,
},
Loop {
body: Block,
span: Span,
},
While {
condition: Box<Self>,
body: Block,
span: Span,
},
For {
pattern: Pattern,
iter: Box<Self>,
body: Block,
span: Span,
},
Return {
value: Option<Box<Self>>,
span: Span,
},
Break {
value: Option<Box<Self>>,
span: Span,
},
Continue {
span: Span,
},
Assign {
target: Box<Self>,
value: Box<Self>,
span: Span,
},
AssignOp {
op: BinOp,
target: Box<Self>,
value: Box<Self>,
span: Span,
},
Reference {
mutable: bool,
expr: Box<Self>,
span: Span,
},
Dereference {
expr: Box<Self>,
span: Span,
},
Cast {
expr: Box<Self>,
ty: Type,
span: Span,
},
Spawn {
expr: Box<Self>,
span: Span,
},
SpawnWithDeadline {
deadline: Box<Self>,
body: Block,
span: Span,
},
TaskGroup {
body: Block,
span: Span,
},
TaskGroupAll {
body: Block,
span: Span,
},
Channel {
element_type: Option<Type>,
capacity: Box<Self>,
span: Span,
},
Select {
arms: Vec<SelectArm>,
span: Span,
},
SelectBiased {
arms: Vec<SelectArm>,
span: Span,
},
Gpu {
body: Block,
span: Span,
},
Distributed {
body: Block,
span: Span,
},
SpawnRemote {
node: Box<Self>,
expr: Box<Self>,
span: Span,
},
Cancelled {
span: Span,
},
EnergyBudgetBlock {
budget: EnergyBudget,
body: Block,
span: Span,
},
ThermalAdapt {
arms: Vec<ThermalArm>,
span: Span,
},
Await {
expr: Box<Self>,
span: Span,
},
Try {
expr: Box<Self>,
span: Span,
},
Closure {
params: Vec<ClosureParam>,
return_type: Option<Type>,
body: Box<Self>,
is_move: bool,
span: Span,
},
Comptime {
body: Block,
span: Span,
},
Perform {
effect: Path,
args: Vec<Self>,
span: Span,
},
Handle {
body: Block,
handlers: Vec<EffectHandler>,
span: Span,
},
Parallel {
pattern: Pattern,
iter: Box<Self>,
body: Block,
span: Span,
},
Build {
builder_ty: Type,
body: Block,
span: Span,
},
}Expand description
Expression
Variants§
Literal(Literal)
Literal: 42, “hello”, true
Ident(Ident)
Identifier: foo
Path(Path)
Path: std::io::Error, Option::None
Macro
Macro invocation: vec![1, 2, 3], println!(“hi”)
Binary
Binary operation: x + y
Unary
Unary operation: -x, !x
Call
Function call: foo(x, y)
MethodCall
Method call: x.foo(y)
Field
Field access: x.y
Index
Index: x[i]
MultiDimIndex
Multi-dimensional index: arr[i, j], arr[1..5, ::2], arr[.., 3]
Range
Range: 0..10, 0..=10
Tuple
Tuple: (x, y, z)
Array
Array: [1, 2, 3]
ArrayRepeat
Array repeat: [0; 10]
Struct
Struct literal: Point { x: 1, y: 2 }
Block(Block)
Block: { stmt1; stmt2; expr }
If
If expression: if cond { a } else { b }
Match
Match expression: match x { … }
Loop
Loop: loop { … }
While
While: while cond { … }
For
For: for x in iter { … }
Return
Return: return x
Break
Break: break
Continue
Continue: continue
Assign
Assignment: x = y
AssignOp
Compound assignment: x += y
Reference
Reference: &x, &mut x
Dereference
Dereference: *x
Cast
Type cast: x as T
Spawn
Spawn a task: spawn expr
SpawnWithDeadline
Spawn a task with deadline: spawn_with_deadline(duration) { … }
TaskGroup
Task group (structured concurrency): task_group { spawn…; spawn…; }
TaskGroupAll
Task group collecting all results: task_group_all { spawn…; }
Channel
Channel creation: channel::
Select
Select expression: select { rx.recv() => |val| …, timeout(dur) => … }
SelectBiased
Biased select: select_biased { … } (first-listed priority)
Gpu
GPU execution block: gpu { … }
Distributed
Distributed execution block: distributed { spawn@node … }
SpawnRemote
Remote spawn: spawn@node expr
Cancelled
Check if current task is cancelled
EnergyBudgetBlock
Energy budget block: energy_budget(max_joules = 0.001) { … }
ThermalAdapt
Thermal adaptation: thermal_adapt { Cool => { … }, Hot => { … } }
Await
Await expression: expr.await
Try
Try operator: expr?
Closure
Closure: |x, y| x + y, |x: i32| -> i32 { x * 2 }, move |x| x
Comptime
Comptime block: comptime { ... } — evaluated at compile time
Perform
Perform an algebraic effect: perform IO::read()
Handle
Handle algebraic effects: handle { body } with { IO => |op| match op { ... } }
Parallel
Parallel for loop: parallel for x in iter { ... }
Build
Result builder expression: build TypeName { stmt1; stmt2; ... }
Inspired by Swift’s @resultBuilder. The builder type provides
build_block, build_expression, build_optional methods that
transform the block’s statements into a single value.