From 3001e907750ce7caa7eaccf73bf990a2f57e4c7d Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 19 Oct 2021 23:52:58 +0800 Subject: [PATCH] Deprecate From for Result> because it is clearer for code to explicitly wrap errors in Err. --- CHANGELOG.md | 9 ++- codegen/Cargo.toml | 4 +- codegen/src/function.rs | 2 +- codegen/src/test/function.rs | 2 +- codegen/src/test/module.rs | 22 ++++---- src/deprecated.rs | 9 +++ src/engine.rs | 88 ++++++++++++++++++------------ src/error.rs | 7 --- src/fn_call.rs | 43 ++++++++------- src/fn_native.rs | 6 +- src/fn_ptr.rs | 2 +- src/fn_register.rs | 8 +-- src/module/resolvers/collection.rs | 2 +- src/module/resolvers/dummy.rs | 2 +- src/packages/array_basic.rs | 47 ++++++++-------- src/packages/iter_basic.rs | 30 ++++++---- src/packages/lang_core.rs | 8 +-- src/packages/logic.rs | 24 ++++---- src/packages/math_basic.rs | 12 ++-- src/packages/string_more.rs | 16 +++--- src/serde/de.rs | 4 +- src/serde/ser.rs | 68 +++++++++++------------ src/serde/str.rs | 4 +- 23 files changed, 226 insertions(+), 193 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f97e900..71e36a06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,9 +7,14 @@ Version 1.2.0 Enhancements ------------ -* `NativeCallContext::call_fn_dynamic_raw` is deprecated and `NativeCallContext::call_fn_raw` is added. * Array methods now avoid cloning as much as possible (although most predicates will involve cloning anyway if passed a closure). -* Inlining is disabled for error-path functions because, most of the time, the script fails completely when an error is encountered. +* Inlining is disabled for error-path functions because errors are exceptional and scripts usually fail completely when an error is encountered. + +Deprecated API's +---------------- + +* `NativeCallContext::call_fn_dynamic_raw` is deprecated and `NativeCallContext::call_fn_raw` is added. +* `From` for `Result>` is deprecated so it will no longer be possible to do `EvalAltResult::ErrorXXXXX.into()` to convert to a `Result`; instead, `Err(EvalAltResult:ErrorXXXXX.into())` must be used. Code is clearer if errors are explicitly wrapped in `Err`. Version 1.1.0 diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 854ad08a..ac70efee 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rhai_codegen" -version = "1.1.0" +version = "1.1.1" edition = "2018" authors = ["jhwgh1968", "Stephen Chung"] description = "Procedural macros support package for Rhai, a scripting language and engine for Rust" @@ -16,7 +16,7 @@ default = [] metadata = [] [dev-dependencies] -rhai = { path = "..", version = "1" } +rhai = { path = "..", version = "1.1" } trybuild = "1" [dependencies] diff --git a/codegen/src/function.rs b/codegen/src/function.rs index 3158cb33..903d9fd6 100644 --- a/codegen/src/function.rs +++ b/codegen/src/function.rs @@ -696,7 +696,7 @@ impl ExportedFn { unpack_statements.push( syn::parse2::(quote! { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant(#arg_lit_str.to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant(#arg_lit_str.to_string(), Position::NONE).into()); } }) .unwrap(), diff --git a/codegen/src/test/function.rs b/codegen/src/test/function.rs index bca0dfdf..02a010b8 100644 --- a/codegen/src/test/function.rs +++ b/codegen/src/test/function.rs @@ -486,7 +486,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg1 = mem::take(args[1usize]).cast::(); let arg0 = &mut args[0usize].write_lock::().unwrap(); diff --git a/codegen/src/test/module.rs b/codegen/src/test/module.rs index abcdc0cc..9075818c 100644 --- a/codegen/src/test/module.rs +++ b/codegen/src/test/module.rs @@ -1096,7 +1096,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg0 = &mut args[0usize].write_lock::().unwrap(); Ok(Dynamic::from(increment(arg0))) @@ -1155,7 +1155,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg0 = &mut args[0usize].write_lock::().unwrap(); Ok(Dynamic::from(increment(arg0))) @@ -1235,7 +1235,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg0 = &mut args[0usize].write_lock::().unwrap(); Ok(Dynamic::from(increment(arg0))) @@ -1316,7 +1316,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg0 = &mut args[0usize].write_lock::().unwrap(); Ok(Dynamic::from(int_foo(arg0))) @@ -1376,7 +1376,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg0 = &mut args[0usize].write_lock::().unwrap(); Ok(Dynamic::from(int_foo(arg0))) @@ -1433,7 +1433,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg1 = mem::take(args[1usize]).cast::(); let arg0 = &mut args[0usize].write_lock::().unwrap(); @@ -1494,7 +1494,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg1 = mem::take(args[1usize]).cast::(); let arg0 = &mut args[0usize].write_lock::().unwrap(); @@ -1552,7 +1552,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg1 = mem::take(args[1usize]).cast::(); let arg0 = &mut args[0usize].write_lock::().unwrap(); @@ -1613,7 +1613,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg1 = mem::take(args[1usize]).cast::(); let arg0 = &mut args[0usize].write_lock::().unwrap(); @@ -1671,7 +1671,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg1 = mem::take(args[1usize]).cast::(); let arg2 = mem::take(args[2usize]).cast::(); @@ -1733,7 +1733,7 @@ mod generate_tests { #[inline(always)] fn call(&self, context: NativeCallContext, args: &mut [&mut Dynamic]) -> RhaiResult { if args[0usize].is_read_only() { - return EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant("x".to_string(), Position::NONE).into()); } let arg1 = mem::take(args[1usize]).cast::(); let arg2 = mem::take(args[2usize]).cast::(); diff --git a/src/deprecated.rs b/src/deprecated.rs index b0485a3e..e4fa7e67 100644 --- a/src/deprecated.rs +++ b/src/deprecated.rs @@ -168,3 +168,12 @@ impl NativeCallContext<'_> { self.call_fn_raw(fn_name.as_ref(), is_method_call, is_method_call, args) } } + +#[allow(useless_deprecated)] +#[deprecated(since = "1.2.0", note = "explicitly wrap `EvalAltResult` in `Err`")] +impl From for Result> { + #[inline(always)] + fn from(err: EvalAltResult) -> Self { + Err(err.into()) + } +} diff --git a/src/engine.rs b/src/engine.rs index c80418f8..84631a2a 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1221,7 +1221,7 @@ impl Engine { return if let Some(val) = this_ptr { Ok(((*val).into(), *pos)) } else { - EvalAltResult::ErrorUnboundThis(*pos).into() + Err(EvalAltResult::ErrorUnboundThis(*pos).into()) } } _ if state.always_search_scope => (0, expr.position()), @@ -1723,7 +1723,7 @@ impl Engine { } } // Syntax error - _ => EvalAltResult::ErrorDotExpr("".into(), rhs.position()).into(), + _ => Err(EvalAltResult::ErrorDotExpr("".into(), rhs.position()).into()), } } } @@ -1958,12 +1958,11 @@ impl Engine { arr_len - index .checked_abs() - .ok_or_else(|| { - EvalAltResult::ErrorArrayBounds(arr_len, index, idx_pos).into() - }) + .ok_or_else(|| EvalAltResult::ErrorArrayBounds(arr_len, index, idx_pos)) .and_then(|n| { if n as usize > arr_len { - EvalAltResult::ErrorArrayBounds(arr_len, index, idx_pos).into() + Err(EvalAltResult::ErrorArrayBounds(arr_len, index, idx_pos) + .into()) } else { Ok(n as usize) } @@ -2014,7 +2013,9 @@ impl Engine { let offset = index as usize; ( if offset >= bits { - return EvalAltResult::ErrorBitFieldBounds(bits, index, idx_pos).into(); + return Err( + EvalAltResult::ErrorBitFieldBounds(bits, index, idx_pos).into() + ); } else { (*value & (1 << offset)) != 0 }, @@ -2025,14 +2026,16 @@ impl Engine { ( // Count from end if negative if offset > bits { - return EvalAltResult::ErrorBitFieldBounds(bits, index, idx_pos).into(); + return Err( + EvalAltResult::ErrorBitFieldBounds(bits, index, idx_pos).into() + ); } else { (*value & (1 << (bits - offset))) != 0 }, offset, ) } else { - return EvalAltResult::ErrorBitFieldBounds(bits, index, idx_pos).into(); + return Err(EvalAltResult::ErrorBitFieldBounds(bits, index, idx_pos).into()); }; Ok(Target::BitField(target, offset, bit_value.into())) @@ -2066,7 +2069,7 @@ impl Engine { ) } else { let chars_len = s.chars().count(); - return EvalAltResult::ErrorStringBounds(chars_len, index, idx_pos).into(); + return Err(EvalAltResult::ErrorStringBounds(chars_len, index, idx_pos).into()); }; Ok(Target::StringChar(target, offset, ch.into())) @@ -2083,7 +2086,7 @@ impl Engine { .map(|(v, _)| v.into()) } - _ => EvalAltResult::ErrorIndexingType( + _ => Err(EvalAltResult::ErrorIndexingType( format!( "{} [{}]", self.map_type_name(target.type_name()), @@ -2091,7 +2094,7 @@ impl Engine { ), Position::NONE, ) - .into(), + .into()), } } @@ -2386,7 +2389,9 @@ impl Engine { ) -> Result<(), Box> { if target.is_read_only() { // Assignment to constant variable - return EvalAltResult::ErrorAssignmentToConstant(root.0.to_string(), root.1).into(); + return Err( + EvalAltResult::ErrorAssignmentToConstant(root.0.to_string(), root.1).into(), + ); } let mut new_val = new_val; @@ -2482,8 +2487,11 @@ impl Engine { .expect("`lhs_ptr` is `Variable`"); if !lhs_ptr.is_ref() { - return EvalAltResult::ErrorAssignmentToConstant(var_name.to_string(), pos) - .into(); + return Err(EvalAltResult::ErrorAssignmentToConstant( + var_name.to_string(), + pos, + ) + .into()); } #[cfg(not(feature = "unchecked"))] @@ -2735,11 +2743,11 @@ impl Engine { if let Some(c) = counter_index { #[cfg(not(feature = "unchecked"))] if x > INT::MAX as usize { - return EvalAltResult::ErrorArithmetic( + return Err(EvalAltResult::ErrorArithmetic( format!("for-loop counter overflow: {}", x), counter.as_ref().expect("`counter` is `Some`").pos, ) - .into(); + .into()); } let mut counter_var = scope @@ -2789,13 +2797,13 @@ impl Engine { scope.rewind(orig_scope_len); Ok(Dynamic::UNIT) } else { - EvalAltResult::ErrorFor(expr.position()).into() + Err(EvalAltResult::ErrorFor(expr.position()).into()) } } // Continue/Break statement Stmt::BreakLoop(options, pos) => { - EvalAltResult::LoopBreak(options.contains(AST_OPTION_BREAK_OUT), *pos).into() + Err(EvalAltResult::LoopBreak(options.contains(AST_OPTION_BREAK_OUT), *pos).into()) } // Namespace-qualified function call @@ -2918,29 +2926,29 @@ impl Engine { // Throw value Stmt::Return(options, Some(expr), pos) if options.contains(AST_OPTION_BREAK_OUT) => { - EvalAltResult::ErrorRuntime( + Err(EvalAltResult::ErrorRuntime( self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)? .flatten(), *pos, ) - .into() + .into()) } // Empty throw Stmt::Return(options, None, pos) if options.contains(AST_OPTION_BREAK_OUT) => { - EvalAltResult::ErrorRuntime(Dynamic::UNIT, *pos).into() + Err(EvalAltResult::ErrorRuntime(Dynamic::UNIT, *pos).into()) } // Return value - Stmt::Return(_, Some(expr), pos) => EvalAltResult::Return( + Stmt::Return(_, Some(expr), pos) => Err(EvalAltResult::Return( self.eval_expr(scope, mods, state, lib, this_ptr, expr, level)? .flatten(), *pos, ) - .into(), + .into()), // Empty return - Stmt::Return(_, None, pos) => EvalAltResult::Return(Dynamic::UNIT, *pos).into(), + Stmt::Return(_, None, pos) => Err(EvalAltResult::Return(Dynamic::UNIT, *pos).into()), // Let/const statement Stmt::Var(expr, x, options, _) => { @@ -3003,7 +3011,7 @@ impl Engine { // Guard against too many modules #[cfg(not(feature = "unchecked"))] if state.num_modules >= self.max_modules() { - return EvalAltResult::ErrorTooManyModules(*_pos).into(); + return Err(EvalAltResult::ErrorTooManyModules(*_pos).into()); } if let Some(path) = self @@ -3032,7 +3040,10 @@ impl Engine { .map(|r| r.resolve(self, source, &path, path_pos)) }) .unwrap_or_else(|| { - EvalAltResult::ErrorModuleNotFound(path.to_string(), path_pos).into() + Err( + EvalAltResult::ErrorModuleNotFound(path.to_string(), path_pos) + .into(), + ) })?; if let Some(name) = export.as_ref().map(|x| x.name.clone()) { @@ -3065,7 +3076,9 @@ impl Engine { if rename.is_empty() { name } else { rename }.clone(), ); } else { - return EvalAltResult::ErrorVariableNotFound(name.to_string(), *pos).into(); + return Err( + EvalAltResult::ErrorVariableNotFound(name.to_string(), *pos).into() + ); } } Ok(Dynamic::UNIT) @@ -3182,11 +3195,11 @@ impl Engine { .max_string_size .map_or(usize::MAX, NonZeroUsize::get) { - return EvalAltResult::ErrorDataTooLarge( + return Err(EvalAltResult::ErrorDataTooLarge( "Length of string".to_string(), Position::NONE, ) - .into(); + .into()); } #[cfg(not(feature = "no_index"))] @@ -3196,8 +3209,11 @@ impl Engine { .max_array_size .map_or(usize::MAX, NonZeroUsize::get) { - return EvalAltResult::ErrorDataTooLarge("Size of array".to_string(), Position::NONE) - .into(); + return Err(EvalAltResult::ErrorDataTooLarge( + "Size of array".to_string(), + Position::NONE, + ) + .into()); } #[cfg(not(feature = "no_object"))] @@ -3207,11 +3223,11 @@ impl Engine { .max_map_size .map_or(usize::MAX, NonZeroUsize::get) { - return EvalAltResult::ErrorDataTooLarge( + return Err(EvalAltResult::ErrorDataTooLarge( "Size of object map".to_string(), Position::NONE, ) - .into(); + .into()); } Ok(()) @@ -3228,14 +3244,14 @@ impl Engine { // Guard against too many operations if self.max_operations() > 0 && state.num_operations > self.max_operations() { - return EvalAltResult::ErrorTooManyOperations(pos).into(); + return Err(EvalAltResult::ErrorTooManyOperations(pos).into()); } // Report progress - only in steps if let Some(ref progress) = self.progress { if let Some(token) = progress(state.num_operations) { // Terminate script if progress returns a termination token - return EvalAltResult::ErrorTerminated(token, pos).into(); + return Err(EvalAltResult::ErrorTerminated(token, pos).into()); } } diff --git a/src/error.rs b/src/error.rs index 52c6fe3c..4cf608fa 100644 --- a/src/error.rs +++ b/src/error.rs @@ -453,10 +453,3 @@ impl EvalAltResult { self } } - -impl From for Result> { - #[inline(always)] - fn from(err: EvalAltResult) -> Self { - Err(err.into()) - } -} diff --git a/src/fn_call.rs b/src/fn_call.rs index 56f26918..87616cc8 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -115,11 +115,11 @@ pub fn ensure_no_data_race( .skip(if is_method_call { 1 } else { 0 }) .find(|(_, a)| a.is_locked()) { - return EvalAltResult::ErrorDataRace( + return Err(EvalAltResult::ErrorDataRace( format!("argument #{} of function '{}'", n + 1, fn_name), Position::NONE, ) - .into(); + .into()); } Ok(()) @@ -392,7 +392,7 @@ impl Engine { crate::engine::FN_IDX_GET => { assert!(args.len() == 2); - EvalAltResult::ErrorIndexingType( + Err(EvalAltResult::ErrorIndexingType( format!( "{} [{}]", self.map_type_name(args[0].type_name()), @@ -400,7 +400,7 @@ impl Engine { ), pos, ) - .into() + .into()) } // index setter function not found? @@ -408,7 +408,7 @@ impl Engine { crate::engine::FN_IDX_SET => { assert!(args.len() == 3); - EvalAltResult::ErrorIndexingType( + Err(EvalAltResult::ErrorIndexingType( format!( "{} [{}] = {}", self.map_type_name(args[0].type_name()), @@ -417,7 +417,7 @@ impl Engine { ), pos, ) - .into() + .into()) } // Getter function not found? @@ -425,7 +425,7 @@ impl Engine { _ if name.starts_with(crate::engine::FN_GET) => { assert!(args.len() == 1); - EvalAltResult::ErrorDotExpr( + Err(EvalAltResult::ErrorDotExpr( format!( "Unknown property '{}' - a getter is not registered for type '{}'", &name[crate::engine::FN_GET.len()..], @@ -433,7 +433,7 @@ impl Engine { ), pos, ) - .into() + .into()) } // Setter function not found? @@ -441,7 +441,7 @@ impl Engine { _ if name.starts_with(crate::engine::FN_SET) => { assert!(args.len() == 2); - EvalAltResult::ErrorDotExpr( + Err(EvalAltResult::ErrorDotExpr( format!( "No writable property '{}' - a setter is not registered for type '{}' to handle '{}'", &name[crate::engine::FN_SET.len()..], @@ -450,14 +450,15 @@ impl Engine { ), pos, ) - .into() + .into()) } // Raise error - _ => { - EvalAltResult::ErrorFunctionNotFound(self.gen_call_signature(None, name, args), pos) - .into() - } + _ => Err(EvalAltResult::ErrorFunctionNotFound( + self.gen_call_signature(None, name, args), + pos, + ) + .into()), } } @@ -489,7 +490,7 @@ impl Engine { err: Box, pos: Position, ) -> RhaiResult { - EvalAltResult::ErrorInFunctionCall( + Err(EvalAltResult::ErrorInFunctionCall( name, fn_def .lib @@ -500,7 +501,7 @@ impl Engine { err, pos, ) - .into() + .into()) } #[cfg(not(feature = "unchecked"))] @@ -514,7 +515,7 @@ impl Engine { #[cfg(not(feature = "no_function"))] #[cfg(not(feature = "unchecked"))] if level > self.max_call_levels() { - return EvalAltResult::ErrorStackOverflow(pos).into(); + return Err(EvalAltResult::ErrorStackOverflow(pos).into()); } let orig_scope_level = state.scope_level; @@ -578,7 +579,7 @@ impl Engine { // System errors are passed straight-through mut err if err.is_system_exception() => { err.set_position(pos); - err.into() + Err(err.into()) } // Other errors are wrapped in `ErrorInFunctionCall` _ => make_error(fn_def.name.to_string(), fn_def, state, err, pos), @@ -651,7 +652,7 @@ impl Engine { ) -> Result<(Dynamic, bool), Box> { fn no_method_err(name: &str, pos: Position) -> Result<(Dynamic, bool), Box> { let msg = format!("'{0}' should not be called this way. Try {0}(...);", name); - EvalAltResult::ErrorRuntime(msg.into(), pos).into() + Err(EvalAltResult::ErrorRuntime(msg.into(), pos).into()) } // Check for data race. @@ -1458,11 +1459,11 @@ impl Engine { Some(f) => unreachable!("unknown function type: {:?}", f), - None => EvalAltResult::ErrorFunctionNotFound( + None => Err(EvalAltResult::ErrorFunctionNotFound( self.gen_call_signature(Some(namespace), fn_name, &args), pos, ) - .into(), + .into()), } } } diff --git a/src/fn_native.rs b/src/fn_native.rs index 15ffbbd6..b47e8eff 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -183,6 +183,9 @@ impl<'a> NativeCallContext<'a> { } /// Call a function inside the call context. /// + /// If `is_method_call` is [`true`], the first argument is assumed to be the + /// `this` pointer for a script-defined function (or the object of a method call). + /// /// # WARNING /// /// All arguments may be _consumed_, meaning that they may be replaced by `()`. @@ -193,9 +196,6 @@ impl<'a> NativeCallContext<'a> { /// /// If `is_ref_mut` is [`true`], the first argument is assumed to be passed /// by reference and is not consumed. - /// - /// If `is_method_call` is [`true`], the first argument is assumed to be the - /// `this` pointer for a script-defined function (or the object of a method call). pub fn call_fn_raw( &self, fn_name: &str, diff --git a/src/fn_ptr.rs b/src/fn_ptr.rs index 6fdf2030..42aa69da 100644 --- a/src/fn_ptr.rs +++ b/src/fn_ptr.rs @@ -148,7 +148,7 @@ impl TryFrom for FnPtr { if is_valid_identifier(value.chars()) { Ok(Self(value, Default::default())) } else { - EvalAltResult::ErrorFunctionNotFound(value.to_string(), Position::NONE).into() + Err(EvalAltResult::ErrorFunctionNotFound(value.to_string(), Position::NONE).into()) } } } diff --git a/src/fn_register.rs b/src/fn_register.rs index 776bace3..fbc74237 100644 --- a/src/fn_register.rs +++ b/src/fn_register.rs @@ -123,7 +123,7 @@ macro_rules! def_register { #[inline(always)] fn into_callable_function(self) -> CallableFunction { CallableFunction::$abi(Box::new(move |ctx: NativeCallContext, args: &mut FnCallArgs| { if args.len() == 2 && args[0].is_read_only() && is_setter(ctx.fn_name()) { - return EvalAltResult::ErrorAssignmentToConstant(Default::default(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant(Default::default(), Position::NONE).into()); } // The arguments are assumed to be of the correct number and types! @@ -151,7 +151,7 @@ macro_rules! def_register { #[inline(always)] fn into_callable_function(self) -> CallableFunction { CallableFunction::$abi(Box::new(move |ctx: NativeCallContext, args: &mut FnCallArgs| { if args.len() == 2 && args[0].is_read_only() && is_setter(ctx.fn_name()) { - return EvalAltResult::ErrorAssignmentToConstant(Default::default(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant(Default::default(), Position::NONE).into()); } // The arguments are assumed to be of the correct number and types! @@ -179,7 +179,7 @@ macro_rules! def_register { #[inline(always)] fn into_callable_function(self) -> CallableFunction { CallableFunction::$abi(Box::new(move |ctx: NativeCallContext, args: &mut FnCallArgs| { if args.len() == 2 && args[0].is_read_only() && is_setter(ctx.fn_name()) { - return EvalAltResult::ErrorAssignmentToConstant(Default::default(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant(Default::default(), Position::NONE).into()); } // The arguments are assumed to be of the correct number and types! @@ -204,7 +204,7 @@ macro_rules! def_register { #[inline(always)] fn into_callable_function(self) -> CallableFunction { CallableFunction::$abi(Box::new(move |ctx: NativeCallContext, args: &mut FnCallArgs| { if args.len() == 2 && args[0].is_read_only() && is_setter(ctx.fn_name()) { - return EvalAltResult::ErrorAssignmentToConstant(Default::default(), Position::NONE).into(); + return Err(EvalAltResult::ErrorAssignmentToConstant(Default::default(), Position::NONE).into()); } // The arguments are assumed to be of the correct number and types! diff --git a/src/module/resolvers/collection.rs b/src/module/resolvers/collection.rs index 55087afe..c6eac580 100644 --- a/src/module/resolvers/collection.rs +++ b/src/module/resolvers/collection.rs @@ -136,7 +136,7 @@ impl ModuleResolver for ModuleResolversCollection { } } - EvalAltResult::ErrorModuleNotFound(path.into(), pos).into() + Err(EvalAltResult::ErrorModuleNotFound(path.into(), pos).into()) } } diff --git a/src/module/resolvers/dummy.rs b/src/module/resolvers/dummy.rs index 15c706f2..904f48ce 100644 --- a/src/module/resolvers/dummy.rs +++ b/src/module/resolvers/dummy.rs @@ -45,6 +45,6 @@ impl ModuleResolver for DummyModuleResolver { path: &str, pos: Position, ) -> Result, Box> { - EvalAltResult::ErrorModuleNotFound(path.into(), pos).into() + Err(EvalAltResult::ErrorModuleNotFound(path.into(), pos).into()) } } diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index 20fc0c7f..342fbd3e 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -79,8 +79,11 @@ mod array_functions { // Check if array will be over max size limit #[cfg(not(feature = "unchecked"))] if _ctx.engine().max_array_size() > 0 && (len as usize) > _ctx.engine().max_array_size() { - return EvalAltResult::ErrorDataTooLarge("Size of array".to_string(), Position::NONE) - .into(); + return Err(EvalAltResult::ErrorDataTooLarge( + "Size of array".to_string(), + Position::NONE, + ) + .into()); } if len as usize > array.len() { @@ -267,13 +270,13 @@ mod array_functions { ctx.call_fn_raw(fn_name, true, false, &mut args)? } _ => { - return EvalAltResult::ErrorInFunctionCall( - "drain".to_string(), + return Err(EvalAltResult::ErrorInFunctionCall( + "map".to_string(), ctx.source().unwrap_or("").to_string(), err, Position::NONE, ) - .into() + .into()) } }, }, @@ -309,13 +312,13 @@ mod array_functions { ctx.call_fn_raw(fn_name, true, false, &mut args)? } _ => { - return EvalAltResult::ErrorInFunctionCall( - "drain".to_string(), + return Err(EvalAltResult::ErrorInFunctionCall( + "filter".to_string(), ctx.source().unwrap_or("").to_string(), err, Position::NONE, ) - .into() + .into()) } }, } @@ -473,13 +476,13 @@ mod array_functions { ctx.call_fn_raw(fn_name, true, false, &mut args)? } _ => { - return EvalAltResult::ErrorInFunctionCall( - "drain".to_string(), + return Err(EvalAltResult::ErrorInFunctionCall( + "index_of".to_string(), ctx.source().unwrap_or("").to_string(), err, Position::NONE, ) - .into() + .into()) } }, } @@ -519,13 +522,13 @@ mod array_functions { ctx.call_fn_raw(fn_name, true, false, &mut args)? } _ => { - return EvalAltResult::ErrorInFunctionCall( - "drain".to_string(), + return Err(EvalAltResult::ErrorInFunctionCall( + "some".to_string(), ctx.source().unwrap_or("").to_string(), err, Position::NONE, ) - .into() + .into()) } }, } @@ -565,13 +568,13 @@ mod array_functions { ctx.call_fn_raw(fn_name, true, false, &mut args)? } _ => { - return EvalAltResult::ErrorInFunctionCall( - "drain".to_string(), + return Err(EvalAltResult::ErrorInFunctionCall( + "all".to_string(), ctx.source().unwrap_or("").to_string(), err, Position::NONE, ) - .into() + .into()) } }, } @@ -781,13 +784,13 @@ mod array_functions { ctx.call_fn_raw(fn_name, true, false, &mut args)? } _ => { - return EvalAltResult::ErrorInFunctionCall( + return Err(EvalAltResult::ErrorInFunctionCall( "drain".to_string(), ctx.source().unwrap_or("").to_string(), err, Position::NONE, ) - .into() + .into()) } }, } @@ -875,13 +878,13 @@ mod array_functions { ctx.call_fn_raw(fn_name, true, false, &mut args)? } _ => { - return EvalAltResult::ErrorInFunctionCall( - "drain".to_string(), + return Err(EvalAltResult::ErrorInFunctionCall( + "retain".to_string(), ctx.source().unwrap_or("").to_string(), err, Position::NONE, ) - .into() + .into()) } }, } diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index 65fb6484..dec48845 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -25,7 +25,7 @@ where #[cfg(not(feature = "unchecked"))] if let Some(r) = from.checked_add(&step) { if r == from { - return EvalAltResult::ErrorInFunctionCall( + return Err(EvalAltResult::ErrorInFunctionCall( "range".to_string(), Default::default(), EvalAltResult::ErrorArithmetic( @@ -35,7 +35,7 @@ where .into(), crate::Position::NONE, ) - .into(); + .into()); } } @@ -122,21 +122,27 @@ impl BitRange { #[cfg(not(feature = "unchecked"))] if offset >= BITS { - return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE) - .into(); + return Err( + EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE).into(), + ); } offset } else { #[cfg(not(feature = "unchecked"))] if let Some(abs_from) = from.checked_abs() { if (abs_from as usize) > BITS { - return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE) - .into(); + return Err(EvalAltResult::ErrorBitFieldBounds( + BITS, + from, + crate::Position::NONE, + ) + .into()); } BITS - (abs_from as usize) } else { - return EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE) - .into(); + return Err( + EvalAltResult::ErrorBitFieldBounds(BITS, from, crate::Position::NONE).into(), + ); } #[cfg(feature = "unchecked")] @@ -325,10 +331,10 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, { pub fn new(from: FLOAT, to: FLOAT, step: FLOAT) -> Result> { #[cfg(not(feature = "unchecked"))] if step == 0.0 { - return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(), + return Err(EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(), EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE).into(), crate::Position::NONE, - ).into(); + ).into()); } Ok(Self(from, to, step)) @@ -387,10 +393,10 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, { pub fn new(from: Decimal, to: Decimal, step: Decimal) -> Result> { #[cfg(not(feature = "unchecked"))] if step.is_zero() { - return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(), + return Err(EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(), EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE).into(), crate::Position::NONE, - ).into(); + ).into()); } Ok(Self(from, to, step)) diff --git a/src/packages/lang_core.rs b/src/packages/lang_core.rs index 26d4c5b0..6c4c76a5 100644 --- a/src/packages/lang_core.rs +++ b/src/packages/lang_core.rs @@ -14,7 +14,7 @@ mod core_functions { #[rhai_fn(name = "set_tag", set = "tag", return_raw)] pub fn set_tag(value: &mut Dynamic, tag: INT) -> Result<(), Box> { if tag < Tag::MIN as INT { - EvalAltResult::ErrorArithmetic( + Err(EvalAltResult::ErrorArithmetic( format!( "{} is too small to fit into a tag (must be between {} and {})", tag, @@ -23,9 +23,9 @@ mod core_functions { ), Position::NONE, ) - .into() + .into()) } else if tag > Tag::MAX as INT { - EvalAltResult::ErrorArithmetic( + Err(EvalAltResult::ErrorArithmetic( format!( "{} is too large to fit into a tag (must be between {} and {})", tag, @@ -34,7 +34,7 @@ mod core_functions { ), Position::NONE, ) - .into() + .into()) } else { value.set_tag(tag as Tag); Ok(()) diff --git a/src/packages/logic.rs b/src/packages/logic.rs index a1fd8d8f..663b29d4 100644 --- a/src/packages/logic.rs +++ b/src/packages/logic.rs @@ -202,7 +202,7 @@ mod bit_field_functions { let offset = index as usize; if offset >= BITS { - EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into() + Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()) } else { Ok((value & (1 << offset)) != 0) } @@ -211,12 +211,12 @@ mod bit_field_functions { // Count from end if negative if offset > BITS { - EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into() + Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()) } else { Ok((value & (1 << (BITS - offset))) != 0) } } else { - EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into() + Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()) } } #[rhai_fn(return_raw)] @@ -225,7 +225,7 @@ mod bit_field_functions { let offset = index as usize; if offset >= BITS { - EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into() + Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()) } else { let mask = 1 << offset; if new_value { @@ -240,7 +240,7 @@ mod bit_field_functions { // Count from end if negative if offset > BITS { - EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into() + Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()) } else { let mask = 1 << offset; if new_value { @@ -251,7 +251,7 @@ mod bit_field_functions { Ok(()) } } else { - EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into() + Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()) } } #[rhai_fn(return_raw)] @@ -264,7 +264,7 @@ mod bit_field_functions { let offset = index as usize; if offset >= BITS { - return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into(); + return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()); } offset @@ -273,11 +273,11 @@ mod bit_field_functions { // Count from end if negative if offset > BITS { - return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into(); + return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()); } BITS - offset } else { - return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into(); + return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()); }; let bits = if offset + bits as usize > BITS { @@ -311,7 +311,7 @@ mod bit_field_functions { let offset = index as usize; if offset >= BITS { - return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into(); + return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()); } offset @@ -320,11 +320,11 @@ mod bit_field_functions { // Count from end if negative if offset > BITS { - return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into(); + return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()); } BITS - offset } else { - return EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into(); + return Err(EvalAltResult::ErrorBitFieldBounds(BITS, index, Position::NONE).into()); }; let bits = if offset + bits as usize > BITS { diff --git a/src/packages/math_basic.rs b/src/packages/math_basic.rs index 0f9f6a88..848d76e8 100644 --- a/src/packages/math_basic.rs +++ b/src/packages/math_basic.rs @@ -114,11 +114,11 @@ mod int_functions { #[rhai_fn(name = "parse_int", return_raw)] pub fn parse_int_radix(string: &str, radix: INT) -> Result> { if !(2..=36).contains(&radix) { - return EvalAltResult::ErrorArithmetic( + return Err(EvalAltResult::ErrorArithmetic( format!("Invalid radix: '{}'", radix), Position::NONE, ) - .into(); + .into()); } INT::from_str_radix(string.trim(), radix as u32).map_err(|err| { @@ -261,11 +261,11 @@ mod float_functions { #[rhai_fn(name = "to_int", return_raw)] pub fn f32_to_int(x: f32) -> Result> { if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f32) { - EvalAltResult::ErrorArithmetic( + Err(EvalAltResult::ErrorArithmetic( format!("Integer overflow: to_int({})", x), Position::NONE, ) - .into() + .into()) } else { Ok(x.trunc() as INT) } @@ -273,11 +273,11 @@ mod float_functions { #[rhai_fn(name = "to_int", return_raw)] pub fn f64_to_int(x: f64) -> Result> { if cfg!(not(feature = "unchecked")) && x > (MAX_INT as f64) { - EvalAltResult::ErrorArithmetic( + Err(EvalAltResult::ErrorArithmetic( format!("Integer overflow: to_int({})", x), Position::NONE, ) - .into() + .into()) } else { Ok(x.trunc() as INT) } diff --git a/src/packages/string_more.rs b/src/packages/string_more.rs index fb8d29e7..02955b09 100644 --- a/src/packages/string_more.rs +++ b/src/packages/string_more.rs @@ -471,11 +471,11 @@ mod string_functions { // Check if string will be over max size limit #[cfg(not(feature = "unchecked"))] if _ctx.engine().max_string_size() > 0 && len as usize > _ctx.engine().max_string_size() { - return crate::EvalAltResult::ErrorDataTooLarge( + return Err(crate::EvalAltResult::ErrorDataTooLarge( "Length of string".to_string(), crate::Position::NONE, ) - .into(); + .into()); } let orig_len = string.chars().count(); @@ -490,11 +490,11 @@ mod string_functions { #[cfg(not(feature = "unchecked"))] if _ctx.engine().max_string_size() > 0 && string.len() > _ctx.engine().max_string_size() { - return crate::EvalAltResult::ErrorDataTooLarge( + return Err(crate::EvalAltResult::ErrorDataTooLarge( "Length of string".to_string(), crate::Position::NONE, ) - .into(); + .into()); } } @@ -516,11 +516,11 @@ mod string_functions { // Check if string will be over max size limit #[cfg(not(feature = "unchecked"))] if _ctx.engine().max_string_size() > 0 && len as usize > _ctx.engine().max_string_size() { - return crate::EvalAltResult::ErrorDataTooLarge( + return Err(crate::EvalAltResult::ErrorDataTooLarge( "Length of string".to_string(), crate::Position::NONE, ) - .into(); + .into()); } let mut str_len = string.chars().count(); @@ -542,11 +542,11 @@ mod string_functions { #[cfg(not(feature = "unchecked"))] if _ctx.engine().max_string_size() > 0 && string.len() > _ctx.engine().max_string_size() { - return crate::EvalAltResult::ErrorDataTooLarge( + return Err(crate::EvalAltResult::ErrorDataTooLarge( "Length of string".to_string(), crate::Position::NONE, ) - .into(); + .into()); } } diff --git a/src/serde/de.rs b/src/serde/de.rs index 3dfc2548..b7c3e67a 100644 --- a/src/serde/de.rs +++ b/src/serde/de.rs @@ -38,12 +38,12 @@ impl<'de> DynamicDeserializer<'de> { } /// Shortcut for a type conversion error. fn type_error_str(&self, error: &str) -> Result> { - EvalAltResult::ErrorMismatchOutputType( + Err(EvalAltResult::ErrorMismatchOutputType( error.into(), self.value.type_name().into(), Position::NONE, ) - .into() + .into()) } fn deserialize_int>( &mut self, diff --git a/src/serde/ser.rs b/src/serde/ser.rs index f42253dc..bfd0d128 100644 --- a/src/serde/ser.rs +++ b/src/serde/ser.rs @@ -313,24 +313,24 @@ impl Serializer for &mut DynamicSerializer { make_variant(_variant, content) } #[cfg(feature = "no_object")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "object maps are not supported with 'no_object'".into(), Position::NONE, ) - .into(); + .into()); } fn serialize_seq(self, _len: Option) -> Result> { #[cfg(not(feature = "no_index"))] return Ok(DynamicSerializer::new(Array::new().into())); #[cfg(feature = "no_index")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "arrays are not supported with 'no_index'".into(), Position::NONE, ) - .into(); + .into()); } fn serialize_tuple(self, len: usize) -> Result> { @@ -359,24 +359,24 @@ impl Serializer for &mut DynamicSerializer { array: Array::with_capacity(_len), }); #[cfg(any(feature = "no_object", feature = "no_index"))] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "tuples are not supported with 'no_index' or 'no_object'".into(), Position::NONE, ) - .into(); + .into()); } fn serialize_map(self, _len: Option) -> Result> { #[cfg(not(feature = "no_object"))] return Ok(DynamicSerializer::new(Map::new().into())); #[cfg(feature = "no_object")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "object maps are not supported with 'no_object'".into(), Position::NONE, ) - .into(); + .into()); } fn serialize_struct( @@ -400,12 +400,12 @@ impl Serializer for &mut DynamicSerializer { map: Default::default(), }); #[cfg(feature = "no_object")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "object maps are not supported with 'no_object'".into(), Position::NONE, ) - .into(); + .into()); } } @@ -425,12 +425,12 @@ impl SerializeSeq for DynamicSerializer { Ok(()) } #[cfg(feature = "no_index")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "arrays are not supported with 'no_index'".into(), Position::NONE, ) - .into(); + .into()); } // Close the sequence. @@ -438,12 +438,12 @@ impl SerializeSeq for DynamicSerializer { #[cfg(not(feature = "no_index"))] return Ok(self._value); #[cfg(feature = "no_index")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "arrays are not supported with 'no_index'".into(), Position::NONE, ) - .into(); + .into()); } } @@ -463,24 +463,24 @@ impl SerializeTuple for DynamicSerializer { Ok(()) } #[cfg(feature = "no_index")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "tuples are not supported with 'no_index'".into(), Position::NONE, ) - .into(); + .into()); } fn end(self) -> Result> { #[cfg(not(feature = "no_index"))] return Ok(self._value); #[cfg(feature = "no_index")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "tuples are not supported with 'no_index'".into(), Position::NONE, ) - .into(); + .into()); } } @@ -500,24 +500,24 @@ impl SerializeTupleStruct for DynamicSerializer { Ok(()) } #[cfg(feature = "no_index")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "tuples are not supported with 'no_index'".into(), Position::NONE, ) - .into(); + .into()); } fn end(self) -> Result> { #[cfg(not(feature = "no_index"))] return Ok(self._value); #[cfg(feature = "no_index")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "tuples are not supported with 'no_index'".into(), Position::NONE, ) - .into(); + .into()); } } @@ -532,12 +532,12 @@ impl SerializeMap for DynamicSerializer { Ok(()) } #[cfg(feature = "no_object")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "object maps are not supported with 'no_object'".into(), Position::NONE, ) - .into(); + .into()); } fn serialize_value( @@ -561,12 +561,12 @@ impl SerializeMap for DynamicSerializer { Ok(()) } #[cfg(feature = "no_object")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "object maps are not supported with 'no_object'".into(), Position::NONE, ) - .into(); + .into()); } fn serialize_entry( @@ -586,24 +586,24 @@ impl SerializeMap for DynamicSerializer { Ok(()) } #[cfg(feature = "no_object")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "object maps are not supported with 'no_object'".into(), Position::NONE, ) - .into(); + .into()); } fn end(self) -> Result> { #[cfg(not(feature = "no_object"))] return Ok(self._value); #[cfg(feature = "no_object")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "object maps are not supported with 'no_object'".into(), Position::NONE, ) - .into(); + .into()); } } @@ -624,24 +624,24 @@ impl SerializeStruct for DynamicSerializer { Ok(()) } #[cfg(feature = "no_object")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "object maps are not supported with 'no_object'".into(), Position::NONE, ) - .into(); + .into()); } fn end(self) -> Result> { #[cfg(not(feature = "no_object"))] return Ok(self._value); #[cfg(feature = "no_object")] - return EvalAltResult::ErrorMismatchDataType( + return Err(EvalAltResult::ErrorMismatchDataType( "".into(), "object maps are not supported with 'no_object'".into(), Position::NONE, ) - .into(); + .into()); } } diff --git a/src/serde/str.rs b/src/serde/str.rs index 81e90f8b..1ad17537 100644 --- a/src/serde/str.rs +++ b/src/serde/str.rs @@ -19,12 +19,12 @@ impl<'a> StringSliceDeserializer<'a> { } /// Shortcut for a type conversion error. fn type_error(&self) -> Result> { - EvalAltResult::ErrorMismatchOutputType( + Err(EvalAltResult::ErrorMismatchOutputType( type_name::().into(), "string".into(), Position::NONE, ) - .into() + .into()) } }