From b7b31bf9da36a9d8a4f7d9673c6db37ae7b87702 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 13 Aug 2015 07:42:06 -0700 Subject: [PATCH] Implement Serialize::visit_newtype_{struct,variant} These functions allow a serializer to not wrap a newtyped value inside of a tuple or struct. --- src/encoder/serde.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/encoder/serde.rs b/src/encoder/serde.rs index 87a742e..3b50181 100644 --- a/src/encoder/serde.rs +++ b/src/encoder/serde.rs @@ -59,6 +59,24 @@ impl ser::Serializer for Encoder { try!(value.serialize(self)); Ok(()) } + fn visit_newtype_struct(&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(&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 {