From c61b11803786523c614eaef406480babbfbe348c Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 3 May 2021 13:57:47 +0800 Subject: [PATCH] Fix decimal build. --- src/dynamic.rs | 2 +- src/packages/iter_basic.rs | 15 +++++++++------ src/packages/math_basic.rs | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/dynamic.rs b/src/dynamic.rs index d58e9d60..b5ea5475 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -705,7 +705,7 @@ impl Clone for Dynamic { #[cfg(not(feature = "no_float"))] Union::Float(value, tag, _) => Self(Union::Float(value, tag, AccessMode::ReadWrite)), #[cfg(feature = "decimal")] - Union::Decimal(ref value, _, _) => { + Union::Decimal(ref value, tag, _) => { Self(Union::Decimal(value.clone(), tag, AccessMode::ReadWrite)) } #[cfg(not(feature = "no_index"))] diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index e09d8923..927821a8 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -246,7 +246,6 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, { #[cfg(feature = "decimal")] { use rust_decimal::Decimal; - use num_traits::Zero; #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)] struct StepDecimalRange(Decimal, Decimal, Decimal); @@ -254,11 +253,15 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, { impl StepDecimalRange { 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(), - Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE)), - crate::Position::NONE, - ).into(); + { + use num_traits::Zero; + + if step.is_zero() { + return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(), + Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE)), + crate::Position::NONE, + ).into(); + } } Ok(Self(from, to, step)) diff --git a/src/packages/math_basic.rs b/src/packages/math_basic.rs index c3e992e0..56cc7105 100644 --- a/src/packages/math_basic.rs +++ b/src/packages/math_basic.rs @@ -307,7 +307,6 @@ mod decimal_functions { prelude::{FromStr, RoundingStrategy}, Decimal, }; - use std::convert::TryFrom; #[rhai_fn(name = "floor", get = "floor")] pub fn floor(x: Decimal) -> Decimal { @@ -424,6 +423,8 @@ mod decimal_functions { #[cfg(not(feature = "no_float"))] pub mod float { + use std::convert::TryFrom; + #[rhai_fn(name = "to_decimal", return_raw)] pub fn f32_to_decimal(x: f32) -> Result> { Decimal::try_from(x).map_err(|_| {