Fix decimal build.
This commit is contained in:
parent
c749bbb653
commit
c61b118037
@ -705,7 +705,7 @@ impl Clone for Dynamic {
|
|||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
Union::Float(value, tag, _) => Self(Union::Float(value, tag, AccessMode::ReadWrite)),
|
Union::Float(value, tag, _) => Self(Union::Float(value, tag, AccessMode::ReadWrite)),
|
||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
Union::Decimal(ref value, _, _) => {
|
Union::Decimal(ref value, tag, _) => {
|
||||||
Self(Union::Decimal(value.clone(), tag, AccessMode::ReadWrite))
|
Self(Union::Decimal(value.clone(), tag, AccessMode::ReadWrite))
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "no_index"))]
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
@ -246,7 +246,6 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
|
|||||||
#[cfg(feature = "decimal")]
|
#[cfg(feature = "decimal")]
|
||||||
{
|
{
|
||||||
use rust_decimal::Decimal;
|
use rust_decimal::Decimal;
|
||||||
use num_traits::Zero;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
|
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
|
||||||
struct StepDecimalRange(Decimal, Decimal, Decimal);
|
struct StepDecimalRange(Decimal, Decimal, Decimal);
|
||||||
@ -254,11 +253,15 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, {
|
|||||||
impl StepDecimalRange {
|
impl StepDecimalRange {
|
||||||
pub fn new(from: Decimal, to: Decimal, step: Decimal) -> Result<Self, Box<EvalAltResult>> {
|
pub fn new(from: Decimal, to: Decimal, step: Decimal) -> Result<Self, Box<EvalAltResult>> {
|
||||||
#[cfg(not(feature = "unchecked"))]
|
#[cfg(not(feature = "unchecked"))]
|
||||||
if step.is_zero() {
|
{
|
||||||
return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(),
|
use num_traits::Zero;
|
||||||
Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE)),
|
|
||||||
crate::Position::NONE,
|
if step.is_zero() {
|
||||||
).into();
|
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))
|
Ok(Self(from, to, step))
|
||||||
|
@ -307,7 +307,6 @@ mod decimal_functions {
|
|||||||
prelude::{FromStr, RoundingStrategy},
|
prelude::{FromStr, RoundingStrategy},
|
||||||
Decimal,
|
Decimal,
|
||||||
};
|
};
|
||||||
use std::convert::TryFrom;
|
|
||||||
|
|
||||||
#[rhai_fn(name = "floor", get = "floor")]
|
#[rhai_fn(name = "floor", get = "floor")]
|
||||||
pub fn floor(x: Decimal) -> Decimal {
|
pub fn floor(x: Decimal) -> Decimal {
|
||||||
@ -424,6 +423,8 @@ mod decimal_functions {
|
|||||||
|
|
||||||
#[cfg(not(feature = "no_float"))]
|
#[cfg(not(feature = "no_float"))]
|
||||||
pub mod float {
|
pub mod float {
|
||||||
|
use std::convert::TryFrom;
|
||||||
|
|
||||||
#[rhai_fn(name = "to_decimal", return_raw)]
|
#[rhai_fn(name = "to_decimal", return_raw)]
|
||||||
pub fn f32_to_decimal(x: f32) -> Result<Decimal, Box<EvalAltResult>> {
|
pub fn f32_to_decimal(x: f32) -> Result<Decimal, Box<EvalAltResult>> {
|
||||||
Decimal::try_from(x).map_err(|_| {
|
Decimal::try_from(x).map_err(|_| {
|
||||||
|
Loading…
Reference in New Issue
Block a user