Introduce RhaiResult.

This commit is contained in:
Stephen Chung
2021-03-02 15:02:28 +08:00
parent 521c8fad27
commit e3e53bd399
13 changed files with 54 additions and 79 deletions

View File

@@ -6,8 +6,7 @@ use crate::fn_native::SendSync;
use crate::stdlib::{boxed::Box, format, string::ToString};
use crate::token::{is_valid_identifier, Token};
use crate::{
Dynamic, Engine, EvalAltResult, ImmutableString, LexError, ParseError, Position, Shared,
StaticVec,
Engine, ImmutableString, LexError, ParseError, Position, RhaiResult, Shared, StaticVec,
};
pub const MARKER_EXPR: &str = "$expr$";
@@ -16,12 +15,10 @@ pub const MARKER_IDENT: &str = "$ident$";
/// A general expression evaluation trait object.
#[cfg(not(feature = "sync"))]
pub type FnCustomSyntaxEval =
dyn Fn(&mut EvalContext, &[Expression]) -> Result<Dynamic, Box<EvalAltResult>>;
pub type FnCustomSyntaxEval = dyn Fn(&mut EvalContext, &[Expression]) -> RhaiResult;
/// A general expression evaluation trait object.
#[cfg(feature = "sync")]
pub type FnCustomSyntaxEval =
dyn Fn(&mut EvalContext, &[Expression]) -> Result<Dynamic, Box<EvalAltResult>> + Send + Sync;
pub type FnCustomSyntaxEval = dyn Fn(&mut EvalContext, &[Expression]) -> RhaiResult + Send + Sync;
/// A general expression parsing trait object.
#[cfg(not(feature = "sync"))]
@@ -68,10 +65,7 @@ impl EvalContext<'_, '_, '_, '_, '_, '_, '_, '_> {
///
/// This function is very low level. It evaluates an expression from an [`AST`][crate::AST].
#[inline(always)]
pub fn eval_expression_tree(
&mut self,
expr: &Expression,
) -> Result<Dynamic, Box<EvalAltResult>> {
pub fn eval_expression_tree(&mut self, expr: &Expression) -> RhaiResult {
self.engine.eval_expr(
self.scope,
self.mods,
@@ -113,9 +107,7 @@ impl Engine {
&mut self,
keywords: &[S],
new_vars: isize,
func: impl Fn(&mut EvalContext, &[Expression]) -> Result<Dynamic, Box<EvalAltResult>>
+ SendSync
+ 'static,
func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static,
) -> Result<&mut Self, ParseError> {
let keywords = keywords.as_ref();
@@ -234,9 +226,7 @@ impl Engine {
+ SendSync
+ 'static,
new_vars: isize,
func: impl Fn(&mut EvalContext, &[Expression]) -> Result<Dynamic, Box<EvalAltResult>>
+ SendSync
+ 'static,
func: impl Fn(&mut EvalContext, &[Expression]) -> RhaiResult + SendSync + 'static,
) -> &mut Self {
let syntax = CustomSyntax {
parse: Box::new(parse),