summaryrefslogtreecommitdiffstats
path: root/vendor/serde_json/src/value
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/serde_json/src/value')
-rw-r--r--vendor/serde_json/src/value/from.rs2
-rw-r--r--vendor/serde_json/src/value/mod.rs8
-rw-r--r--vendor/serde_json/src/value/partial_eq.rs10
-rw-r--r--vendor/serde_json/src/value/ser.rs43
4 files changed, 48 insertions, 15 deletions
diff --git a/vendor/serde_json/src/value/from.rs b/vendor/serde_json/src/value/from.rs
index c5a6a3960..462ad3f51 100644
--- a/vendor/serde_json/src/value/from.rs
+++ b/vendor/serde_json/src/value/from.rs
@@ -40,7 +40,7 @@ impl From<f32> for Value {
/// let x: Value = f.into();
/// ```
fn from(f: f32) -> Self {
- From::from(f as f64)
+ Number::from_f32(f).map_or(Value::Null, Value::Number)
}
}
diff --git a/vendor/serde_json/src/value/mod.rs b/vendor/serde_json/src/value/mod.rs
index c467df6cc..470b6b24d 100644
--- a/vendor/serde_json/src/value/mod.rs
+++ b/vendor/serde_json/src/value/mod.rs
@@ -85,10 +85,10 @@
//! # untyped_example().unwrap();
//! ```
//!
-//! [macro]: https://docs.serde.rs/serde_json/macro.json.html
-//! [from_str]: https://docs.serde.rs/serde_json/de/fn.from_str.html
-//! [from_slice]: https://docs.serde.rs/serde_json/de/fn.from_slice.html
-//! [from_reader]: https://docs.serde.rs/serde_json/de/fn.from_reader.html
+//! [macro]: crate::json
+//! [from_str]: crate::de::from_str
+//! [from_slice]: crate::de::from_slice
+//! [from_reader]: crate::de::from_reader
use crate::error::Error;
use crate::io;
diff --git a/vendor/serde_json/src/value/partial_eq.rs b/vendor/serde_json/src/value/partial_eq.rs
index b4ef84c4f..6b2e350b6 100644
--- a/vendor/serde_json/src/value/partial_eq.rs
+++ b/vendor/serde_json/src/value/partial_eq.rs
@@ -9,6 +9,13 @@ fn eq_u64(value: &Value, other: u64) -> bool {
value.as_u64().map_or(false, |i| i == other)
}
+fn eq_f32(value: &Value, other: f32) -> bool {
+ match value {
+ Value::Number(n) => n.as_f32().map_or(false, |i| i == other),
+ _ => false,
+ }
+}
+
fn eq_f64(value: &Value, other: f64) -> bool {
value.as_f64().map_or(false, |i| i == other)
}
@@ -90,6 +97,7 @@ macro_rules! partialeq_numeric {
partialeq_numeric! {
eq_i64[i8 i16 i32 i64 isize]
eq_u64[u8 u16 u32 u64 usize]
- eq_f64[f32 f64]
+ eq_f32[f32]
+ eq_f64[f64]
eq_bool[bool]
}
diff --git a/vendor/serde_json/src/value/ser.rs b/vendor/serde_json/src/value/ser.rs
index 892a63d5f..875d22e24 100644
--- a/vendor/serde_json/src/value/ser.rs
+++ b/vendor/serde_json/src/value/ser.rs
@@ -1,10 +1,11 @@
use crate::error::{Error, ErrorCode, Result};
use crate::map::Map;
-use crate::number::Number;
use crate::value::{to_value, Value};
use alloc::borrow::ToOwned;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
+#[cfg(not(feature = "arbitrary_precision"))]
+use core::convert::TryFrom;
use core::fmt::Display;
use core::result;
use serde::ser::{Impossible, Serialize};
@@ -92,9 +93,22 @@ impl serde::Serializer for Serializer {
Ok(Value::Number(value.into()))
}
- #[cfg(feature = "arbitrary_precision")]
fn serialize_i128(self, value: i128) -> Result<Value> {
- Ok(Value::Number(value.into()))
+ #[cfg(feature = "arbitrary_precision")]
+ {
+ Ok(Value::Number(value.into()))
+ }
+
+ #[cfg(not(feature = "arbitrary_precision"))]
+ {
+ if let Ok(value) = u64::try_from(value) {
+ Ok(Value::Number(value.into()))
+ } else if let Ok(value) = i64::try_from(value) {
+ Ok(Value::Number(value.into()))
+ } else {
+ Err(Error::syntax(ErrorCode::NumberOutOfRange, 0, 0))
+ }
+ }
}
#[inline]
@@ -117,19 +131,30 @@ impl serde::Serializer for Serializer {
Ok(Value::Number(value.into()))
}
- #[cfg(feature = "arbitrary_precision")]
fn serialize_u128(self, value: u128) -> Result<Value> {
- Ok(Value::Number(value.into()))
+ #[cfg(feature = "arbitrary_precision")]
+ {
+ Ok(Value::Number(value.into()))
+ }
+
+ #[cfg(not(feature = "arbitrary_precision"))]
+ {
+ if let Ok(value) = u64::try_from(value) {
+ Ok(Value::Number(value.into()))
+ } else {
+ Err(Error::syntax(ErrorCode::NumberOutOfRange, 0, 0))
+ }
+ }
}
#[inline]
- fn serialize_f32(self, value: f32) -> Result<Value> {
- self.serialize_f64(value as f64)
+ fn serialize_f32(self, float: f32) -> Result<Value> {
+ Ok(Value::from(float))
}
#[inline]
- fn serialize_f64(self, value: f64) -> Result<Value> {
- Ok(Number::from_f64(value).map_or(Value::Null, Value::Number))
+ fn serialize_f64(self, float: f64) -> Result<Value> {
+ Ok(Value::from(float))
}
#[inline]