aboutsummaryrefslogtreecommitdiff
path: root/src/private
diff options
context:
space:
mode:
Diffstat (limited to 'src/private')
-rw-r--r--src/private/de.rs25
-rw-r--r--src/private/ser.rs8
2 files changed, 22 insertions, 11 deletions
diff --git a/src/private/de.rs b/src/private/de.rs
index f0697d6..e9c693d 100644
--- a/src/private/de.rs
+++ b/src/private/de.rs
@@ -1262,6 +1262,17 @@ mod content {
{
match self.content {
Content::Unit => visitor.visit_unit(),
+
+ // Allow deserializing newtype variant containing unit.
+ //
+ // #[derive(Deserialize)]
+ // #[serde(tag = "result")]
+ // enum Response<T> {
+ // Success(T),
+ // }
+ //
+ // We want {"result":"Success"} to deserialize into Response<()>.
+ Content::Map(ref v) if v.is_empty() => visitor.visit_unit(),
_ => Err(self.invalid_type(&visitor)),
}
}
@@ -1799,7 +1810,7 @@ mod content {
V: Visitor<'de>,
E: de::Error,
{
- let map = content.iter().map(|&(ref k, ref v)| {
+ let map = content.iter().map(|(k, v)| {
(
ContentRefDeserializer::new(k),
ContentRefDeserializer::new(v),
@@ -2096,7 +2107,7 @@ mod content {
let (variant, value) = match *self.content {
Content::Map(ref value) => {
let mut iter = value.iter();
- let &(ref variant, ref value) = match iter.next() {
+ let (variant, value) = match iter.next() {
Some(v) => v,
None => {
return Err(de::Error::invalid_value(
@@ -2243,7 +2254,7 @@ mod content {
V: de::Visitor<'de>,
{
match self.value {
- Some(&Content::Seq(ref v)) => {
+ Some(Content::Seq(v)) => {
de::Deserializer::deserialize_any(SeqRefDeserializer::new(v), visitor)
}
Some(other) => Err(de::Error::invalid_type(
@@ -2266,10 +2277,10 @@ mod content {
V: de::Visitor<'de>,
{
match self.value {
- Some(&Content::Map(ref v)) => {
+ Some(Content::Map(v)) => {
de::Deserializer::deserialize_any(MapRefDeserializer::new(v), visitor)
}
- Some(&Content::Seq(ref v)) => {
+ Some(Content::Seq(v)) => {
de::Deserializer::deserialize_any(SeqRefDeserializer::new(v), visitor)
}
Some(other) => Err(de::Error::invalid_type(
@@ -2392,7 +2403,7 @@ mod content {
T: de::DeserializeSeed<'de>,
{
match self.iter.next() {
- Some(&(ref key, ref value)) => {
+ Some((key, value)) => {
self.value = Some(value);
seed.deserialize(ContentRefDeserializer::new(key)).map(Some)
}
@@ -2697,7 +2708,7 @@ where
#[cfg(any(feature = "std", feature = "alloc"))]
macro_rules! forward_to_deserialize_other {
- ($($func:ident ( $($arg:ty),* ))*) => {
+ ($($func:ident ($($arg:ty),*))*) => {
$(
fn $func<V>(self, $(_: $arg,)* _visitor: V) -> Result<V::Value, Self::Error>
where
diff --git a/src/private/ser.rs b/src/private/ser.rs
index 6ee9993..528e8c1 100644
--- a/src/private/ser.rs
+++ b/src/private/ser.rs
@@ -51,7 +51,6 @@ enum Unsupported {
String,
ByteArray,
Optional,
- Unit,
#[cfg(any(feature = "std", feature = "alloc"))]
UnitStruct,
Sequence,
@@ -70,7 +69,6 @@ impl Display for Unsupported {
Unsupported::String => formatter.write_str("a string"),
Unsupported::ByteArray => formatter.write_str("a byte array"),
Unsupported::Optional => formatter.write_str("an optional"),
- Unsupported::Unit => formatter.write_str("unit"),
#[cfg(any(feature = "std", feature = "alloc"))]
Unsupported::UnitStruct => formatter.write_str("unit struct"),
Unsupported::Sequence => formatter.write_str("a sequence"),
@@ -184,7 +182,9 @@ where
}
fn serialize_unit(self) -> Result<Self::Ok, Self::Error> {
- Err(self.bad_type(Unsupported::Unit))
+ let mut map = try!(self.delegate.serialize_map(Some(1)));
+ try!(map.serialize_entry(self.tag, self.variant_name));
+ map.end()
}
fn serialize_unit_struct(self, _: &'static str) -> Result<Self::Ok, Self::Error> {
@@ -525,7 +525,7 @@ mod content {
Content::Map(ref entries) => {
use ser::SerializeMap;
let mut map = try!(serializer.serialize_map(Some(entries.len())));
- for &(ref k, ref v) in entries {
+ for (k, v) in entries {
try!(map.serialize_entry(k, v));
}
map.end()