Fix f32_feature with serde.

This commit is contained in:
Stephen Chung 2021-04-06 23:18:28 +08:00
parent 131147c65d
commit 7ec49a9510
3 changed files with 8 additions and 6 deletions

View File

@ -23,10 +23,10 @@ jobs:
- "--features sync" - "--features sync"
- "--features no_optimize" - "--features no_optimize"
- "--features no_float" - "--features no_float"
- "--features f32_float" - "--features f32_float,serde,metadata,internals"
- "--features decimal" - "--features decimal"
- "--features no_float,decimal" - "--features no_float,decimal"
- "--tests --features only_i32" - "--tests --features only_i32,serde,metadata,internals"
- "--features only_i64" - "--features only_i64"
- "--features no_index" - "--features no_index"
- "--features no_object" - "--features no_object"

View File

@ -26,7 +26,7 @@ impl Serialize for Dynamic {
Union::Float(x, _) => ser.serialize_f64(**x), Union::Float(x, _) => ser.serialize_f64(**x),
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
#[cfg(feature = "f32_float")] #[cfg(feature = "f32_float")]
Union::Float(x, _) => ser.serialize_f32(*x), Union::Float(x, _) => ser.serialize_f32(**x),
#[cfg(feature = "decimal")] #[cfg(feature = "decimal")]
#[cfg(not(feature = "f32_float"))] #[cfg(not(feature = "f32_float"))]

View File

@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize};
use rhai::Array; use rhai::Array;
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
use rhai::Map; use rhai::Map;
#[cfg(not(feature = "no_float"))]
use rhai::FLOAT;
#[cfg(feature = "decimal")] #[cfg(feature = "decimal")]
use rust_decimal::Decimal; use rust_decimal::Decimal;
@ -358,7 +360,7 @@ fn test_serde_de_primary_types() -> Result<(), Box<EvalAltResult>> {
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
{ {
assert_eq!(123.456, from_dynamic::<f64>(&123.456_f64.into())?); assert_eq!(123.456, from_dynamic::<FLOAT>(&123.456.into())?);
assert_eq!(123.456, from_dynamic::<f32>(&Dynamic::from(123.456_f32))?); assert_eq!(123.456, from_dynamic::<f32>(&Dynamic::from(123.456_f32))?);
} }
@ -447,8 +449,8 @@ fn test_serde_de_struct() -> Result<(), Box<EvalAltResult>> {
fn test_serde_de_script() -> Result<(), Box<EvalAltResult>> { fn test_serde_de_script() -> Result<(), Box<EvalAltResult>> {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct Point { struct Point {
x: f64, x: FLOAT,
y: f64, y: FLOAT,
} }
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]