Use type alias

This commit is contained in:
Stephen Chung
2021-12-25 23:49:14 +08:00
parent 43363e0660
commit 01c35808cb
42 changed files with 538 additions and 702 deletions

View File

@@ -2,7 +2,7 @@
use crate::{
Dynamic, Engine, EvalAltResult, Expression, FnPtr, ImmutableString, NativeCallContext,
RhaiResult, Scope, AST,
RhaiResult, RhaiResultOf, Scope, AST,
};
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
@@ -22,7 +22,7 @@ impl Engine {
#[cfg(not(feature = "no_std"))]
#[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))]
#[inline(always)]
pub fn consume_file(&self, path: std::path::PathBuf) -> Result<(), Box<EvalAltResult>> {
pub fn consume_file(&self, path: std::path::PathBuf) -> RhaiResultOf<()> {
self.run_file(path)
}
@@ -44,7 +44,7 @@ impl Engine {
&self,
scope: &mut Scope,
path: std::path::PathBuf,
) -> Result<(), Box<EvalAltResult>> {
) -> RhaiResultOf<()> {
self.run_file_with_scope(scope, path)
}
@@ -58,7 +58,7 @@ impl Engine {
/// This method will be removed in the next major version.
#[deprecated(since = "1.1.0", note = "use `run` instead")]
#[inline(always)]
pub fn consume(&self, script: &str) -> Result<(), Box<EvalAltResult>> {
pub fn consume(&self, script: &str) -> RhaiResultOf<()> {
self.run(script)
}
@@ -72,11 +72,7 @@ impl Engine {
/// This method will be removed in the next major version.
#[deprecated(since = "1.1.0", note = "use `run_with_scope` instead")]
#[inline(always)]
pub fn consume_with_scope(
&self,
scope: &mut Scope,
script: &str,
) -> Result<(), Box<EvalAltResult>> {
pub fn consume_with_scope(&self, scope: &mut Scope, script: &str) -> RhaiResultOf<()> {
self.run_with_scope(scope, script)
}
@@ -90,7 +86,7 @@ impl Engine {
/// This method will be removed in the next major version.
#[deprecated(since = "1.1.0", note = "use `run_ast` instead")]
#[inline(always)]
pub fn consume_ast(&self, ast: &AST) -> Result<(), Box<EvalAltResult>> {
pub fn consume_ast(&self, ast: &AST) -> RhaiResultOf<()> {
self.run_ast(ast)
}
@@ -104,11 +100,7 @@ impl Engine {
/// This method will be removed in the next major version.
#[deprecated(since = "1.1.0", note = "use `run_ast_with_scope` instead")]
#[inline(always)]
pub fn consume_ast_with_scope(
&self,
scope: &mut Scope,
ast: &AST,
) -> Result<(), Box<EvalAltResult>> {
pub fn consume_ast_with_scope(&self, scope: &mut Scope, ast: &AST) -> RhaiResultOf<()> {
self.run_ast_with_scope(scope, ast)
}
/// Call a script function defined in an [`AST`] with multiple [`Dynamic`] arguments
@@ -258,7 +250,7 @@ impl NativeCallContext<'_> {
#[allow(useless_deprecated)]
#[deprecated(since = "1.2.0", note = "explicitly wrap `EvalAltResult` in `Err`")]
impl<T> From<EvalAltResult> for Result<T, Box<EvalAltResult>> {
impl<T> From<EvalAltResult> for RhaiResultOf<T> {
#[inline(always)]
fn from(err: EvalAltResult) -> Self {
Err(err.into())