Allow serializing newtype struct to Formatter

Serialize_newtype_struct is typically expected to just pass through the
wrapped value.
This commit is contained in:
David Tolnay 2020-05-09 17:31:20 -07:00
parent 850a29beb1
commit 35ad468780
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -54,6 +54,13 @@ impl<'a, 'b> Serializer for &'a mut fmt::Formatter<'b> {
Display::fmt(variant, self)
}
fn serialize_newtype_struct<T: ?Sized>(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<T: ?Sized>(self, _name: &'static str, _value: &T) -> fmt::Result
where
T: Serialize,
{
Err(fmt::Error)
}
fn serialize_newtype_variant<T: ?Sized>(
self,
_name: &'static str,