From 7ec49a95108da61a50ea2072a5ba6ef86de9ebb5 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 6 Apr 2021 23:18:28 +0800 Subject: [PATCH] Fix f32_feature with serde. --- .github/workflows/build.yml | 4 ++-- src/serde/serialize.rs | 2 +- tests/serde.rs | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26553d24..8687601c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,10 +23,10 @@ jobs: - "--features sync" - "--features no_optimize" - "--features no_float" - - "--features f32_float" + - "--features f32_float,serde,metadata,internals" - "--features decimal" - "--features no_float,decimal" - - "--tests --features only_i32" + - "--tests --features only_i32,serde,metadata,internals" - "--features only_i64" - "--features no_index" - "--features no_object" diff --git a/src/serde/serialize.rs b/src/serde/serialize.rs index e5f3f6a4..ba75842a 100644 --- a/src/serde/serialize.rs +++ b/src/serde/serialize.rs @@ -26,7 +26,7 @@ impl Serialize for Dynamic { Union::Float(x, _) => ser.serialize_f64(**x), #[cfg(not(feature = "no_float"))] #[cfg(feature = "f32_float")] - Union::Float(x, _) => ser.serialize_f32(*x), + Union::Float(x, _) => ser.serialize_f32(**x), #[cfg(feature = "decimal")] #[cfg(not(feature = "f32_float"))] diff --git a/tests/serde.rs b/tests/serde.rs index 8ee666c4..f8557062 100644 --- a/tests/serde.rs +++ b/tests/serde.rs @@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize}; use rhai::Array; #[cfg(not(feature = "no_object"))] use rhai::Map; +#[cfg(not(feature = "no_float"))] +use rhai::FLOAT; #[cfg(feature = "decimal")] use rust_decimal::Decimal; @@ -358,7 +360,7 @@ fn test_serde_de_primary_types() -> Result<(), Box> { #[cfg(not(feature = "no_float"))] { - assert_eq!(123.456, from_dynamic::(&123.456_f64.into())?); + assert_eq!(123.456, from_dynamic::(&123.456.into())?); assert_eq!(123.456, from_dynamic::(&Dynamic::from(123.456_f32))?); } @@ -447,8 +449,8 @@ fn test_serde_de_struct() -> Result<(), Box> { fn test_serde_de_script() -> Result<(), Box> { #[derive(Debug, Deserialize)] struct Point { - x: f64, - y: f64, + x: FLOAT, + y: FLOAT, } #[derive(Debug, Deserialize)]