Struct rhai::Expression

source ·
pub struct Expression<'a>(_);
Expand description

An expression sub-tree in an AST.

Implementations§

source§

impl Expression<'_>

source

pub fn eval_with_context( &self, context: &mut EvalContext<'_, '_, '_, '_, '_, '_> ) -> Result<Dynamic, Box<EvalAltResult>>

Evaluate this expression tree within an evaluation context.

WARNING - Low Level API

This function is very low level. It evaluates an expression from an AST.

source

pub fn eval_with_context_raw( &self, context: &mut EvalContext<'_, '_, '_, '_, '_, '_>, rewind_scope: bool ) -> Result<Dynamic, Box<EvalAltResult>>

👎Deprecated: This API is NOT deprecated, but it is considered volatile and may change in the future.

Evaluate this expression tree within an evaluation context.

The following option is available:

  • whether to rewind the Scope after evaluation if the expression is a StmtBlock
WARNING - Unstable API

This API is volatile and may change in the future.

WARNING - Low Level API

This function is extremely low level. It evaluates an expression from an AST.

source

pub fn get_string_value(&self) -> Option<&str>

Get the value of this expression if it is a variable name or a string constant.

Returns None also if the constant is not of the specified type.

source

pub const fn position(&self) -> Position

Get the position of this expression.

source

pub fn get_literal_value<T: Variant>(&self) -> Option<T>

Get the value of this expression if it is a literal constant.

Supports INT, FLOAT, (), char, bool and ImmutableString.

Returns None also if the constant is not of the specified type.

source§

impl Expression<'_>

source

pub fn get_variable_name(&self) -> Option<&str>

👎Deprecated since 1.4.0: use <code>get_string_value</code> instead

If this expression is a variable name, return it. Otherwise None.

Deprecated

This method is deprecated. Use get_string_value instead.

This method will be removed in the next major version.

Methods from Deref<Target = 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 options(&self) -> ASTFlags

Get the options of the expression.

source

pub 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 is_pure(&self) -> bool

Is the expression pure?

A pure expression has no side effects.

source

pub 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 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<'a> Clone for Expression<'a>

source§

fn clone(&self) -> Expression<'a>

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<'a> Debug for Expression<'a>

source§

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

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

impl Deref for Expression<'_>

§

type Target = Expr

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

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

source§

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

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Expression<'a>

§

impl<'a> !Send for Expression<'a>

§

impl<'a> !Sync for Expression<'a>

§

impl<'a> Unpin for Expression<'a>

§

impl<'a> !UnwindSafe for Expression<'a>

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.