From 35ad468780438176ca14a0e514859f714496cd79 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 9 May 2020 17:31:20 -0700 Subject: [PATCH] Allow serializing newtype struct to Formatter Serialize_newtype_struct is typically expected to just pass through the wrapped value. --- serde/src/ser/fmt.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/serde/src/ser/fmt.rs b/serde/src/ser/fmt.rs index bc9623c6..f6e890d4 100644 --- a/serde/src/ser/fmt.rs +++ b/serde/src/ser/fmt.rs @@ -54,6 +54,13 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> { Display::fmt(variant, self) } + fn serialize_newtype_struct(self, _name: &'static str, value: &T) -> fmt::Result + where + T: Serialize, + { + Serialize::serialize(value, self) + } + fn serialize_bytes(self, _v: &[u8]) -> fmt::Result { Err(fmt::Error) } @@ -73,13 +80,6 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> { Err(fmt::Error) } - fn serialize_newtype_struct(self, _name: &'static str, _value: &T) -> fmt::Result - where - T: Serialize, - { - Err(fmt::Error) - } - fn serialize_newtype_variant( self, _name: &'static str,