Skip to main content

Expr

Enum Expr 

Source
pub enum Expr {
Show 38 variants IntLiteral(i64), FloatLiteral(f64), StringLiteral(String), CharLiteral(char), BoolLiteral(bool), Ident(String), BinaryOp { left: Box<Expr>, op: BinOp, right: Box<Expr>, }, UnaryOp { op: UnaryOp, expr: Box<Expr>, }, Assign { target: Box<Expr>, value: Box<Expr>, }, CompoundAssign { target: Box<Expr>, op: BinOp, value: Box<Expr>, }, Let { name: String, mutable: bool, type_ann: Option<Type>, value: Option<Box<Expr>>, }, Block(Vec<Expr>), If { condition: Box<Expr>, then_block: Box<Expr>, else_block: Option<Box<Expr>>, }, While { condition: Box<Expr>, body: Box<Expr>, }, Loop { body: Box<Expr>, }, For { var: String, iterator: Box<Expr>, body: Box<Expr>, }, Range { start: Option<Box<Expr>>, end: Option<Box<Expr>>, inclusive: bool, }, Break(Option<Box<Expr>>), Continue, Return(Option<Box<Expr>>), FnDef { name: String, params: Vec<(String, Type)>, return_type: Option<Type>, body: Box<Expr>, }, FnCall { name: String, args: Vec<Expr>, }, MethodCall { object: Box<Expr>, method: String, args: Vec<Expr>, }, MacroCall { name: String, args: Vec<Expr>, }, ArrayLiteral(Vec<Expr>), ArrayRepeat { value: Box<Expr>, count: Box<Expr>, }, TupleLiteral(Vec<Expr>), Index { object: Box<Expr>, index: Box<Expr>, }, FieldAccess { object: Box<Expr>, field: String, }, StructDef { name: String, fields: Vec<(String, Type)>, }, StructInit { name: String, fields: Vec<(String, Expr)>, }, Match { expr: Box<Expr>, arms: Vec<MatchArm>, }, TypeCast { expr: Box<Expr>, target_type: Type, }, Closure { params: Vec<(String, Option<Type>)>, body: Box<Expr>, }, Ref { expr: Box<Expr>, mutable: bool, }, Deref(Box<Expr>), VecMacro(Vec<Expr>), Unit,
}
Expand description

An expression or statement in the AST.

In VirtualRust, everything is an expression — even let bindings, if/while/for control flow, and function definitions.

Variants§

§

IntLiteral(i64)

§

FloatLiteral(f64)

§

StringLiteral(String)

§

CharLiteral(char)

§

BoolLiteral(bool)

§

Ident(String)

§

BinaryOp

Fields

§left: Box<Expr>
§right: Box<Expr>
§

UnaryOp

Fields

§expr: Box<Expr>
§

Assign

Simple assignment (x = expr).

Fields

§target: Box<Expr>
§value: Box<Expr>
§

CompoundAssign

Compound assignment (x += expr, x -= expr, etc.).

Fields

§target: Box<Expr>
§value: Box<Expr>
§

Let

Variable declaration (let [mut] name [: type] = expr).

Fields

§name: String
§mutable: bool
§type_ann: Option<Type>
§value: Option<Box<Expr>>
§

Block(Vec<Expr>)

A { ... } block of statements.

§

If

if condition { ... } [else { ... }]

Fields

§condition: Box<Expr>
§then_block: Box<Expr>
§else_block: Option<Box<Expr>>
§

While

Fields

§condition: Box<Expr>
§body: Box<Expr>
§

Loop

Fields

§body: Box<Expr>
§

For

Fields

§iterator: Box<Expr>
§body: Box<Expr>
§

Range

Fields

§start: Option<Box<Expr>>
§inclusive: bool
§

Break(Option<Box<Expr>>)

§

Continue

§

Return(Option<Box<Expr>>)

§

FnDef

Named function definition.

Fields

§name: String
§params: Vec<(String, Type)>
§return_type: Option<Type>
§body: Box<Expr>
§

FnCall

Fields

§name: String
§args: Vec<Expr>
§

MethodCall

Fields

§object: Box<Expr>
§method: String
§args: Vec<Expr>
§

MacroCall

Fields

§name: String
§args: Vec<Expr>
§

ArrayLiteral(Vec<Expr>)

[a, b, c]

§

ArrayRepeat

[expr; count]

Fields

§value: Box<Expr>
§count: Box<Expr>
§

TupleLiteral(Vec<Expr>)

§

Index

Fields

§object: Box<Expr>
§index: Box<Expr>
§

FieldAccess

Fields

§object: Box<Expr>
§field: String
§

StructDef

struct Name { ... }

Fields

§name: String
§fields: Vec<(String, Type)>
§

StructInit

Fields

§name: String
§fields: Vec<(String, Expr)>
§

Match

match expr { arms... }

Fields

§expr: Box<Expr>
§

TypeCast

expr as Type

Fields

§expr: Box<Expr>
§target_type: Type
§

Closure

|params| body

Fields

§params: Vec<(String, Option<Type>)>
§body: Box<Expr>
§

Ref

&expr or &mut expr

Fields

§expr: Box<Expr>
§mutable: bool
§

Deref(Box<Expr>)

*expr

§

VecMacro(Vec<Expr>)

vec![...]

§

Unit

The unit value ().

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

Auto Trait Implementations§

§

impl Freeze for Expr

§

impl RefUnwindSafe for Expr

§

impl Send for Expr

§

impl Sync for Expr

§

impl Unpin for Expr

§

impl UnsafeUnpin 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.