Introduce RhaiResult.
This commit is contained in:
@@ -7,7 +7,7 @@ use crate::fn_native::{CallableFunction, FnAny, FnCallArgs, SendSync};
|
||||
use crate::r#unsafe::unsafe_cast_box;
|
||||
use crate::stdlib::{any::TypeId, boxed::Box, mem, string::String};
|
||||
use crate::{
|
||||
Dynamic, Engine, EvalAltResult, FnAccess, FnNamespace, ImmutableString, NativeCallContext,
|
||||
Dynamic, Engine, FnAccess, FnNamespace, ImmutableString, NativeCallContext, RhaiResult,
|
||||
};
|
||||
|
||||
/// Trait to register custom functions with the [`Engine`].
|
||||
@@ -52,7 +52,7 @@ pub trait RegisterResultFn<FN, ARGS> {
|
||||
/// use rhai::{Engine, Dynamic, RegisterResultFn, EvalAltResult};
|
||||
///
|
||||
/// // Normal function
|
||||
/// fn div(x: i64, y: i64) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
/// fn div(x: i64, y: i64) -> RhaiResult {
|
||||
/// if y == 0 {
|
||||
/// // '.into()' automatically converts to 'Box<EvalAltResult::ErrorRuntime>'
|
||||
/// Err("division by zero!".into())
|
||||
@@ -142,15 +142,13 @@ macro_rules! make_func {
|
||||
|
||||
/// To Dynamic mapping function.
|
||||
#[inline(always)]
|
||||
pub fn map_dynamic(data: impl Variant + Clone) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
pub fn map_dynamic(data: impl Variant + Clone) -> RhaiResult {
|
||||
Ok(data.into_dynamic())
|
||||
}
|
||||
|
||||
/// To Dynamic mapping function.
|
||||
#[inline(always)]
|
||||
pub fn map_result(
|
||||
data: Result<Dynamic, Box<EvalAltResult>>,
|
||||
) -> Result<Dynamic, Box<EvalAltResult>> {
|
||||
pub fn map_result(data: RhaiResult) -> RhaiResult {
|
||||
data
|
||||
}
|
||||
|
||||
@@ -197,7 +195,7 @@ macro_rules! def_register {
|
||||
|
||||
impl<
|
||||
$($par: Variant + Clone,)*
|
||||
FN: Fn($($param),*) -> Result<Dynamic, Box<EvalAltResult>> + SendSync + 'static,
|
||||
FN: Fn($($param),*) -> RhaiResult + SendSync + 'static,
|
||||
> RegisterResultFn<FN, ($($mark,)*)> for Engine
|
||||
{
|
||||
#[inline]
|
||||
|
Reference in New Issue
Block a user