Skip to main content

PureExpr

Enum PureExpr 

Source
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

§op: String

Operator token (e.g. +, ==).

§left: Box<PureExpr>

Left operand.

§right: Box<PureExpr>

Right operand.

§

Unary

Unary operation: -x, !x, *x, &x

Fields

§op: String

Operator token (- / ! / * / &).

§expr: Box<PureExpr>

Operand expression.

§

Call

Function call: foo(a, b)

Fields

§func: Box<PureExpr>

Callee expression.

§args: Vec<PureExpr>

Argument expressions.

§

MethodCall

Method call: x.foo(a, b) or x.foo::<T>(a, b)

Fields

§receiver: Box<PureExpr>

Receiver expression (LHS of .).

§method: String

Method name.

§turbofish: Option<String>

Turbofish type arguments: ::<T, U>"< T , U >"

§args: Vec<PureExpr>

Argument expressions.

§

Field

Field access: x.field

Fields

§expr: Box<PureExpr>

Base expression.

§field: String

Field name (or tuple index as string).

§

Index

Index: x[i]

Fields

§expr: Box<PureExpr>

Base expression (x).

§index: Box<PureExpr>

Index expression (i).

§

Block

Block: { ... } or 'label: { ... }

Fields

§label: Option<String>

Optional label (e.g., 'block)

§block: PureBlock

Inner block.

§

If

If: if cond { ... } else { ... }

Fields

§cond: Box<PureExpr>

Condition expression.

§then_branch: PureBlock

then branch block.

§else_branch: Option<Box<PureExpr>>

Optional else branch (another expression).

§

Match

Match: match x { ... }

Fields

§expr: Box<PureExpr>

Scrutinee expression.

§arms: Vec<PureMatchArm>

Match arms.

§

Loop

Loop: loop { ... } or 'label: loop { ... }

Fields

§label: Option<String>

Optional label (e.g., 'outer)

§body: PureBlock

Loop body block.

§

While

While: while cond { ... } or 'label: while cond { ... }

Fields

§label: Option<String>

Optional label (e.g., 'outer)

§cond: Box<PureExpr>

Loop condition.

§body: PureBlock

Loop body block.

§

For

For: for pat in expr { ... } or 'label: for pat in expr { ... }

Fields

§label: Option<String>

Optional label (e.g., 'outer)

§pat: PurePattern

Iteration binding pattern.

§expr: Box<PureExpr>

Iterator expression.

§body: PureBlock

Loop body block.

§

Return(Option<Box<PureExpr>>)

Return: return x

§

Break

Break: break x or break 'label x

Fields

§label: Option<String>

Optional label to break to (e.g., 'outer)

§expr: Option<Box<PureExpr>>

Optional value carried out of the loop.

§

Continue

Continue: continue or continue 'label

Fields

§label: Option<String>

Optional label to continue to (e.g., 'outer)

§

Closure

Closure: |x| x + 1, |x: Foo| -> Bar { x }, move |x| x

Fields

§is_async: bool

Is async closure?

§is_move: bool

Is move closure?

§params: Vec<PureClosureParam>

Parameters with optional type annotations.

§ret: Option<PureType>

Optional return type annotation.

§body: Box<PureExpr>

Closure body expression.

§

Struct

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

Fields

§path: String

Struct path (e.g. Point).

§fields: Vec<(String, PureExpr)>

Field initializers (name, expr).

§

Tuple(Vec<PureExpr>)

Tuple: (a, b, c)

§

Array(Vec<PureExpr>)

Array: [1, 2, 3]

§

Ref

Reference: &x, &mut x

Fields

§is_mut: bool

mut qualifier (&mut).

§expr: Box<PureExpr>

Referent expression.

§

Macro

Macro invocation: println!(...)

Fields

§name: String

Macro name (without !).

§delimiter: MacroDelimiter

Delimiter style around tokens.

§tokens: String

Raw token stream as a string.

§

Await(Box<PureExpr>)

Await: x.await

§

Try(Box<PureExpr>)

Try: x?

§

Range

Range: a..b, ..b, a.., .., a..=b

Fields

§start: Option<Box<PureExpr>>

Start bound expression (None = unbounded).

§end: Option<Box<PureExpr>>

End bound expression (None = unbounded).

§inclusive: bool

true for ..=, false for ..

§

Cast

Cast: x as T

Fields

§expr: Box<PureExpr>

Source expression.

§ty: PureType

Target type.

§

Let

Let expression (in conditions): let Some(x) = y

Fields

§pattern: PurePattern

Pattern on the LHS of let.

§expr: Box<PureExpr>

Scrutinee expression on the RHS.

§

Async

Async block: async { ... } or async move { ... }

Fields

§is_move: bool

move qualifier.

§body: PureBlock

Async block body.

§

Unsafe(PureBlock)

Unsafe block: unsafe { ... }

§

Repeat

Array repeat: [expr; N]

Fields

§expr: Box<PureExpr>

Element expression to repeat.

§len: Box<PureExpr>

Repeat count expression.

§

Other(String)

Other (as string).

Implementations§

Source§

impl PureExpr

Source

pub fn method_call( receiver: Box<PureExpr>, method: String, args: Vec<PureExpr>, ) -> Self

Create a MethodCall with default turbofish (None)

Source

pub fn closure(params: Vec<PureClosureParam>, body: Box<PureExpr>) -> Self

Create a Closure with untyped params and no return type annotation.

Source

pub fn get_child(&self, index: usize) -> Option<&PureExpr>

Get child expression at index.

Index mapping varies by variant:

  • Binary: 0=left, 1=right
  • Unary, Field, Ref, Await, Try, Cast, Let: 0=expr
  • Call: 0=func, 1..=args
  • MethodCall: 0=receiver, 1..=args
  • Index, Repeat: 0=expr, 1=index/len
  • Range: 0=start, 1=end (if present)
  • If: 0=cond, 1=else_branch (if present)
  • While, For: 0=cond/expr
  • Match: 0=expr
  • Return, Break: 0=inner (if present)
  • Closure: 0=body
  • Tuple, Array: 0..n=elements
  • Struct: 0..n=field values
  • Others: None
Source

pub fn get_child_mut(&mut self, index: usize) -> Option<&mut PureExpr>

Get mutable child expression at index.

Source

pub fn get_block(&self) -> Option<&PureBlock>

Get the contained block (for Block, Loop, Async, Unsafe, If, While, For).

Source

pub fn get_block_mut(&mut self) -> Option<&mut PureBlock>

Get mutable contained block.

Source

pub fn child_count(&self) -> usize

Number of direct child expressions.

Source

pub fn navigate(&self, path: &[usize]) -> Option<&PureExpr>

Navigate to a nested expression by path (slice of indices).

§Example
// For: x.foo(a + b, c)
// Path [1, 0] navigates to: args[0].left = `a`
expr.navigate(&[1, 0])
Source

pub fn navigate_mut(&mut self, path: &[usize]) -> Option<&mut PureExpr>

Navigate to a nested expression mutably.

Trait Implementations§

Source§

impl Clone for PureExpr

Source§

fn clone(&self) -> PureExpr

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for PureExpr

Source§

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

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

impl PartialEq for PureExpr

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 ToSyn for PureExpr

Source§

type Output = Expr

syn output type produced from self.
Source§

fn to_syn(&self) -> Result<Expr, ToSynError>

Convert self back into its syn representation.
Source§

impl Eq for PureExpr

Source§

impl StructuralPartialEq for PureExpr

Auto Trait Implementations§

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.