diff --git a/CHANGELOG.md b/CHANGELOG.md index 4bcba46a..cd6a6e1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ Enhancements * Added `FnPtr::call` and `FnPtr::call_within_context` to simplify calling a function pointer. * BLob's can now be deserialized (using `from_dynamic`) into `Vec` via [`serde_bytes`](https://crates.io/crates/serde_bytes). * A function's hashes are included in its JSON metadata to assist in debugging. Each function's `hashBase` field in the JSON object should map directly to the pre-calculated hash in the function call. +* `Expression` now derefs to `Expr`. Deprecated and Gated API's -------------------------- diff --git a/src/custom_syntax.rs b/src/custom_syntax.rs index 03802854..56e96c5f 100644 --- a/src/custom_syntax.rs +++ b/src/custom_syntax.rs @@ -10,9 +10,9 @@ use crate::{ Engine, Identifier, ImmutableString, LexError, ParseError, Position, RhaiResult, Shared, StaticVec, INT, }; -use std::any::TypeId; #[cfg(feature = "no_std")] use std::prelude::v1::*; +use std::{any::TypeId, ops::Deref}; /// Collection of special markers for custom syntax definition. pub mod markers { @@ -71,12 +71,6 @@ impl Expression<'_> { pub fn get_variable_name(&self) -> Option<&str> { self.0.get_variable_name(true) } - /// Get the expression. - #[inline(always)] - #[must_use] - pub(crate) const fn expr(&self) -> &Expr { - &self.0 - } /// Get the position of this expression. #[inline(always)] #[must_use] @@ -134,6 +128,22 @@ impl Expression<'_> { } } +impl AsRef for Expression<'_> { + #[inline(always)] + fn as_ref(&self) -> &Expr { + &self.0 + } +} + +impl Deref for Expression<'_> { + type Target = Expr; + + #[inline(always)] + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl EvalContext<'_, '_, '_, '_, '_, '_, '_, '_> { /// Evaluate an [expression tree][Expression]. /// @@ -148,7 +158,7 @@ impl EvalContext<'_, '_, '_, '_, '_, '_, '_, '_> { self.state, self.lib, self.this_ptr, - expr.expr(), + expr, self.level, ) }