Implement Serialize::visit_newtype_{struct,variant}

These functions allow a serializer to not wrap a newtyped value
inside of a tuple or struct.
This commit is contained in:
Erick Tryzelaar 2015-08-13 07:42:06 -07:00
parent bbc167cde9
commit b7b31bf9da

View file

@ -59,6 +59,24 @@ impl ser::Serializer for Encoder {
try!(value.serialize(self)); try!(value.serialize(self));
Ok(()) Ok(())
} }
fn visit_newtype_struct<T>(&mut self,
_name: &'static str,
value: T) -> Result<(), Self::Error>
where T: ser::Serialize,
{
// Don't serialize the newtype struct in a tuple.
value.serialize(self)
}
fn visit_newtype_variant<T>(&mut self,
_name: &'static str,
_variant_index: usize,
_variant: &'static str,
value: T) -> Result<(), Self::Error>
where T: ser::Serialize,
{
// Don't serialize the newtype struct variant in a tuple.
value.serialize(self)
}
} }
impl ser::Serialize for Value { impl ser::Serialize for Value {