mirror of
https://github.com/serde-rs/json.git
synced 2026-03-13 17:57:45 +00:00
Merge pull request #643 from serde-rs/nostd
Improve error message when neither std nor alloc is enabled
This commit is contained in:
commit
4752793b4a
@ -10,7 +10,7 @@ use crate::lib::borrow::Borrow;
|
||||
use crate::lib::iter::FromIterator;
|
||||
use crate::lib::*;
|
||||
use crate::value::Value;
|
||||
use serde::{de, ser};
|
||||
use serde::de;
|
||||
|
||||
#[cfg(feature = "preserve_order")]
|
||||
use indexmap::{self, IndexMap};
|
||||
@ -289,11 +289,12 @@ impl Debug for Map<String, Value> {
|
||||
}
|
||||
}
|
||||
|
||||
impl ser::Serialize for Map<String, Value> {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
impl serde::ser::Serialize for Map<String, Value> {
|
||||
#[inline]
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: ser::Serializer,
|
||||
S: serde::ser::Serializer,
|
||||
{
|
||||
use serde::ser::SerializeMap;
|
||||
let mut map = tri!(serializer.serialize_map(Some(self.len())));
|
||||
@ -327,6 +328,7 @@ impl<'de> de::Deserialize<'de> for Map<String, Value> {
|
||||
Ok(Map::new())
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[inline]
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<Self::Value, V::Error>
|
||||
where
|
||||
|
||||
@ -48,6 +48,7 @@ impl<'de> Deserialize<'de> for Value {
|
||||
Ok(Number::from_f64(value).map_or(Value::Null, Value::Number))
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[inline]
|
||||
fn visit_str<E>(self, value: &str) -> Result<Value, E>
|
||||
where
|
||||
@ -56,6 +57,7 @@ impl<'de> Deserialize<'de> for Value {
|
||||
self.visit_string(String::from(value))
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
#[inline]
|
||||
fn visit_string<E>(self, value: String) -> Result<Value, E> {
|
||||
Ok(Value::String(value))
|
||||
@ -93,6 +95,7 @@ impl<'de> Deserialize<'de> for Value {
|
||||
Ok(Value::Array(vec))
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
fn visit_map<V>(self, mut visitor: V) -> Result<Value, V::Error>
|
||||
where
|
||||
V: MapAccess<'de>,
|
||||
@ -208,6 +211,7 @@ impl<'de> serde::Deserializer<'de> for Value {
|
||||
Value::Null => visitor.visit_unit(),
|
||||
Value::Bool(v) => visitor.visit_bool(v),
|
||||
Value::Number(n) => n.deserialize_any(visitor),
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
Value::String(v) => visitor.visit_string(v),
|
||||
Value::Array(v) => visit_array(v, visitor),
|
||||
Value::Object(v) => visit_object(v, visitor),
|
||||
@ -338,6 +342,7 @@ impl<'de> serde::Deserializer<'de> for Value {
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
Value::String(v) => visitor.visit_string(v),
|
||||
_ => Err(self.invalid_type(&visitor)),
|
||||
}
|
||||
@ -355,6 +360,7 @@ impl<'de> serde::Deserializer<'de> for Value {
|
||||
V: Visitor<'de>,
|
||||
{
|
||||
match self {
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
Value::String(v) => visitor.visit_string(v),
|
||||
Value::Array(v) => visit_array(v, visitor),
|
||||
_ => Err(self.invalid_type(&visitor)),
|
||||
@ -1225,6 +1231,7 @@ macro_rules! deserialize_integer_key {
|
||||
match (self.key.parse(), self.key) {
|
||||
(Ok(integer), _) => visitor.$visit(integer),
|
||||
(Err(_), Cow::Borrowed(s)) => visitor.visit_borrowed_str(s),
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
(Err(_), Cow::Owned(s)) => visitor.visit_string(s),
|
||||
}
|
||||
}
|
||||
@ -1337,6 +1344,7 @@ impl<'de> Visitor<'de> for KeyClassifier {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
fn visit_string<E>(self, s: String) -> Result<Self::Value, E>
|
||||
where
|
||||
E: de::Error,
|
||||
@ -1392,6 +1400,7 @@ impl<'de> de::Deserializer<'de> for BorrowedCowStrDeserializer<'de> {
|
||||
{
|
||||
match self.value {
|
||||
Cow::Borrowed(string) => visitor.visit_borrowed_str(string),
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
Cow::Owned(string) => visitor.visit_string(string),
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ impl Serialize for Value {
|
||||
Value::Number(ref n) => n.serialize(serializer),
|
||||
Value::String(ref s) => serializer.serialize_str(s),
|
||||
Value::Array(ref v) => v.serialize(serializer),
|
||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||
Value::Object(ref m) => {
|
||||
use serde::ser::SerializeMap;
|
||||
let mut map = tri!(serializer.serialize_map(Some(m.len())));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user