Struct rhai::Expression
source · pub struct Expression<'a>(/* private fields */);
Expand description
An expression sub-tree in an AST
.
Implementations§
source§impl Expression<'_>
impl Expression<'_>
sourcepub fn eval_with_context(
&self,
context: &mut EvalContext<'_, '_, '_, '_, '_, '_>
) -> Result<Dynamic, Box<EvalAltResult>>
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
.
sourcepub 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.
pub fn eval_with_context_raw( &self, context: &mut EvalContext<'_, '_, '_, '_, '_, '_>, rewind_scope: bool ) -> Result<Dynamic, Box<EvalAltResult>>
Evaluate this expression tree within an evaluation context.
The following option is available:
§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
.
sourcepub fn get_string_value(&self) -> Option<&str>
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.
sourcepub fn get_literal_value<T: Variant>(&self) -> Option<T>
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<'_>
impl Expression<'_>
sourcepub fn get_variable_name(&self) -> Option<&str>
👎Deprecated since 1.4.0: use get_string_value
instead
pub fn get_variable_name(&self) -> Option<&str>
get_string_value
insteadIf 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>§
sourcepub fn get_literal_value(&self) -> Option<Dynamic>
pub fn get_literal_value(&self) -> Option<Dynamic>
sourcepub fn start_position(&self) -> Position
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.
sourcepub fn is_constant(&self) -> bool
pub fn is_constant(&self) -> bool
Is the expression a constant?
sourcepub fn is_valid_postfix(&self, token: &Token) -> bool
pub fn is_valid_postfix(&self, token: &Token) -> bool
Is a particular token allowed as a postfix operator to this expression?
Trait Implementations§
source§impl AsRef<Expr> for Expression<'_>
impl AsRef<Expr> for Expression<'_>
source§impl Borrow<Expr> for Expression<'_>
impl Borrow<Expr> for Expression<'_>
source§impl<'a> Clone for Expression<'a>
impl<'a> Clone for Expression<'a>
source§fn clone(&self) -> Expression<'a>
fn clone(&self) -> Expression<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'a> Debug for Expression<'a>
impl<'a> Debug for Expression<'a>
source§impl Deref for Expression<'_>
impl Deref for Expression<'_>
Auto Trait Implementations§
impl<'a> Freeze for Expression<'a>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Variant for T
impl<T> Variant for T
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Variant
trait object to &mut dyn Any
.source§fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
fn as_boxed_any(self: Box<T>) -> Box<dyn Any>
Variant
trait object to Box<dyn Any>
.