Expr

Enum Expr 

Source
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”)

Fields

§name: Path
§args: Vec<Self>
§span: Span
§

Binary

Binary operation: x + y

Fields

§left: Box<Self>
§right: Box<Self>
§span: Span
§

Unary

Unary operation: -x, !x

Fields

§op: UnOp
§expr: Box<Self>
§span: Span
§

Call

Function call: foo(x, y)

Fields

§func: Box<Self>
§args: Vec<Self>
§span: Span
§

MethodCall

Method call: x.foo(y)

Fields

§receiver: Box<Self>
§method: Ident
§args: Vec<Self>
§span: Span
§

Field

Field access: x.y

Fields

§expr: Box<Self>
§field: Ident
§span: Span
§

Index

Index: x[i]

Fields

§expr: Box<Self>
§index: Box<Self>
§span: Span
§

MultiDimIndex

Multi-dimensional index: arr[i, j], arr[1..5, ::2], arr[.., 3]

Fields

§expr: Box<Self>
§span: Span
§

Range

Range: 0..10, 0..=10

Fields

§start: Option<Box<Self>>
§end: Option<Box<Self>>
§inclusive: bool
§span: Span
§

Tuple

Tuple: (x, y, z)

Fields

§elements: Vec<Self>
§span: Span
§

Array

Array: [1, 2, 3]

Fields

§elements: Vec<Self>
§span: Span
§

ArrayRepeat

Array repeat: [0; 10]

Fields

§element: Box<Self>
§count: Box<Self>
§span: Span
§

Struct

Struct literal: Point { x: 1, y: 2 }

Fields

§path: Path
§fields: Vec<FieldInit>
§span: Span
§

Block(Block)

Block: { stmt1; stmt2; expr }

§

If

If expression: if cond { a } else { b }

Fields

§condition: Box<Self>
§then_block: Block
§else_block: Option<Box<Self>>
§span: Span
§

Match

Match expression: match x { … }

Fields

§expr: Box<Self>
§span: Span
§

Loop

Loop: loop { … }

Fields

§body: Block
§span: Span
§

While

While: while cond { … }

Fields

§condition: Box<Self>
§body: Block
§span: Span
§

For

For: for x in iter { … }

Fields

§pattern: Pattern
§iter: Box<Self>
§body: Block
§span: Span
§

Return

Return: return x

Fields

§value: Option<Box<Self>>
§span: Span
§

Break

Break: break

Fields

§value: Option<Box<Self>>
§span: Span
§

Continue

Continue: continue

Fields

§span: Span
§

Assign

Assignment: x = y

Fields

§target: Box<Self>
§value: Box<Self>
§span: Span
§

AssignOp

Compound assignment: x += y

Fields

§target: Box<Self>
§value: Box<Self>
§span: Span
§

Reference

Reference: &x, &mut x

Fields

§mutable: bool
§expr: Box<Self>
§span: Span
§

Dereference

Dereference: *x

Fields

§expr: Box<Self>
§span: Span
§

Cast

Type cast: x as T

Fields

§expr: Box<Self>
§ty: Type
§span: Span
§

Spawn

Spawn a task: spawn expr

Fields

§expr: Box<Self>
§span: Span
§

SpawnWithDeadline

Spawn a task with deadline: spawn_with_deadline(duration) { … }

Fields

§deadline: Box<Self>
§body: Block
§span: Span
§

TaskGroup

Task group (structured concurrency): task_group { spawn…; spawn…; }

Fields

§body: Block
§span: Span
§

TaskGroupAll

Task group collecting all results: task_group_all { spawn…; }

Fields

§body: Block
§span: Span
§

Channel

Channel creation: channel::(capacity)

Fields

§element_type: Option<Type>
§capacity: Box<Self>
§span: Span
§

Select

Select expression: select { rx.recv() => |val| …, timeout(dur) => … }

Fields

§span: Span
§

SelectBiased

Biased select: select_biased { … } (first-listed priority)

Fields

§span: Span
§

Gpu

GPU execution block: gpu { … }

Fields

§body: Block
§span: Span
§

Distributed

Distributed execution block: distributed { spawn@node … }

Fields

§body: Block
§span: Span
§

SpawnRemote

Remote spawn: spawn@node expr

Fields

§node: Box<Self>
§expr: Box<Self>
§span: Span
§

Cancelled

Check if current task is cancelled

Fields

§span: Span
§

EnergyBudgetBlock

Energy budget block: energy_budget(max_joules = 0.001) { … }

Fields

§body: Block
§span: Span
§

ThermalAdapt

Thermal adaptation: thermal_adapt { Cool => { … }, Hot => { … } }

Fields

§span: Span
§

Await

Await expression: expr.await

Fields

§expr: Box<Self>
§span: Span
§

Try

Try operator: expr?

Fields

§expr: Box<Self>
§span: Span
§

Closure

Closure: |x, y| x + y, |x: i32| -> i32 { x * 2 }, move |x| x

Fields

§return_type: Option<Type>
§body: Box<Self>
§is_move: bool
§span: Span
§

Comptime

Comptime block: comptime { ... } — evaluated at compile time

Fields

§body: Block
§span: Span
§

Perform

Perform an algebraic effect: perform IO::read()

Fields

§effect: Path
§args: Vec<Self>
§span: Span
§

Handle

Handle algebraic effects: handle { body } with { IO => |op| match op { ... } }

Fields

§body: Block
§handlers: Vec<EffectHandler>
§span: Span
§

Parallel

Parallel for loop: parallel for x in iter { ... }

Fields

§pattern: Pattern
§iter: Box<Self>
§body: Block
§span: Span
§

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.

Fields

§builder_ty: Type
§body: Block
§span: Span

Implementations§

Source§

impl Expr

Source

pub const fn span(&self) -> Span

Trait Implementations§

Source§

impl Clone for Expr

Source§

fn clone(&self) -> Expr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Expr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Expr

Source§

fn eq(&self, other: &Expr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Expr

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnwindSafe for Expr

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.