Enum rhai::Expr

source ·
#[non_exhaustive]
pub enum Expr {
Show 21 variants DynamicConstant(Box<Dynamic>, Position), BoolConstant(bool, Position), IntegerConstant(INT, Position), FloatConstant(FloatWrapper<FLOAT>, Position), CharConstant(char, Position), StringConstant(ImmutableString, Position), InterpolatedString(Box<StaticVec<Expr>>, Position), Array(Box<StaticVec<Expr>>, Position), Map(Box<(StaticVec<(Ident, Expr)>, BTreeMap<Identifier, Dynamic>)>, Position), Unit(Position), Variable(Box<(Option<NonZeroUsize>, Namespace, u64, ImmutableString)>, Option<NonZeroU8>, Position), Property(Box<((ImmutableString, u64), (ImmutableString, u64), ImmutableString)>, Position), MethodCall(Box<FnCallExpr>, Position), Stmt(Box<StmtBlock>), FnCall(Box<FnCallExpr>, Position), Dot(Box<BinaryExpr>, ASTFlags, Position), Index(Box<BinaryExpr>, ASTFlags, Position), And(Box<BinaryExpr>, Position), Or(Box<BinaryExpr>, Position), Coalesce(Box<BinaryExpr>, Position), Custom(Box<CustomExpr>, Position),
}
Expand description

(internals) An expression sub-tree. Exported under the internals feature only.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

DynamicConstant(Box<Dynamic>, Position)

Dynamic constant.

Used to hold complex constants such as Array or Map for quick cloning. Primitive data types should use the appropriate variants to avoid an allocation.

The Dynamic value is boxed in order to avoid bloating the size of Expr.

§

BoolConstant(bool, Position)

Boolean constant.

§

IntegerConstant(INT, Position)

Integer constant.

§

FloatConstant(FloatWrapper<FLOAT>, Position)

Floating-point constant.

§

CharConstant(char, Position)

Character constant.

§

StringConstant(ImmutableString, Position)

String constant.

§

InterpolatedString(Box<StaticVec<Expr>>, Position)

An interpolated string.

§

Array(Box<StaticVec<Expr>>, Position)

[ expr, … ]

§

Map(Box<(StaticVec<(Ident, Expr)>, BTreeMap<Identifier, Dynamic>)>, Position)

#{ name:expr, … }

§

Unit(Position)

()

§

Variable(Box<(Option<NonZeroUsize>, Namespace, u64, ImmutableString)>, Option<NonZeroU8>, Position)

Variable access - (optional long index, namespace, namespace hash, variable name), optional short index, position

The short index is u8 which is used when the index is <= 255, which should be the vast majority of cases (unless there are more than 255 variables defined!). This is to avoid reading a pointer redirection during each variable access.

§

Property(Box<((ImmutableString, u64), (ImmutableString, u64), ImmutableString)>, Position)

Property access - ((getter, hash), (setter, hash), prop)

§

MethodCall(Box<FnCallExpr>, Position)

xxx . method ( expr ,)

§

Stmt(Box<StmtBlock>)

{ statement … }

§

FnCall(Box<FnCallExpr>, Position)

func ( expr ,)

§

Dot(Box<BinaryExpr>, ASTFlags, Position)

lhs . rhs | lhs ?. rhs

Flags

NEGATED = ?. (. if unset) BREAK = terminate the chain (recurse into the chain if unset)

§

Index(Box<BinaryExpr>, ASTFlags, Position)

lhs [ rhs ]

Flags

NEGATED = ?[] ([] if unset) BREAK = terminate the chain (recurse into the chain if unset)

§

And(Box<BinaryExpr>, Position)

lhs && rhs

§

Or(Box<BinaryExpr>, Position)

lhs || rhs

§

Coalesce(Box<BinaryExpr>, Position)

lhs ?? rhs

§

Custom(Box<CustomExpr>, Position)

Custom syntax

Implementations§

source§

impl Expr

source

pub fn get_literal_value(&self) -> Option<Dynamic>

Get the Dynamic value of a literal constant expression.

Returns None if the expression is not a literal constant.

source

pub fn from_dynamic(value: Dynamic, pos: Position) -> Self

Create an Expr from a Dynamic value.

source

pub const fn options(&self) -> ASTFlags

Get the options of the expression.

source

pub const fn position(&self) -> Position

Get the position of the expression.

source

pub fn start_position(&self) -> Position

Get the starting position of the expression. For a binary expression, this will be the left-most LHS instead of the operator.

source

pub fn set_position(&mut self, new_pos: Position) -> &mut Self

Override the position of the expression.

source

pub fn is_pure(&self) -> bool

Is the expression pure?

A pure expression has no side effects.

source

pub const fn is_unit(&self) -> bool

Is the expression the unit () literal?

source

pub fn is_constant(&self) -> bool

Is the expression a constant?

source

pub const fn is_valid_postfix(&self, token: &Token) -> bool

Is a particular token allowed as a postfix operator to this expression?

source

pub fn walk<'a>( &'a self, path: &mut Vec<ASTNode<'a>>, on_node: &mut impl FnMut(&[ASTNode<'_>]) -> bool ) -> bool

Recursively walk this expression. Return false from the callback to terminate the walk.

Trait Implementations§

source§

impl AsRef<Expr> for Expression<'_>

source§

fn as_ref(&self) -> &Expr

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<Expr> for Expression<'_>

source§

fn borrow(&self) -> &Expr

Immutably borrows from an owned value. Read more
source§

impl Clone for Expr

source§

fn clone(&self) -> Expr

Returns a copy 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 Default for Expr

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'a> From<&'a Expr> for ASTNode<'a>

source§

fn from(expr: &'a Expr) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a Expr> for Expression<'a>

source§

fn from(expr: &'a Expr) -> Self

Converts to this type from the input type.
source§

impl Hash for Expr

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more

Auto Trait Implementations§

§

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 Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.