Skip to content

Commit

Permalink
Implement Serialize::visit_newtype_{struct,variant}
Browse files Browse the repository at this point in the history
These functions allow a serializer to not wrap a newtyped value
inside of a tuple or struct.
  • Loading branch information
erickt committed Aug 13, 2015
1 parent bbc167c commit b7b31bf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/encoder/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ impl ser::Serializer for Encoder {
try!(value.serialize(self));
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 {
Expand Down

0 comments on commit b7b31bf

Please sign in to comment.