From 3e937ec145b627fdf9447902e10797cd70c26b8b Mon Sep 17 00:00:00 2001 From: Tom Dohrmann Date: Sun, 18 Apr 2021 15:35:46 +0200 Subject: [PATCH] add support for unit_variant --- src/ser.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/ser.rs b/src/ser.rs index 86a4dbf..fe8c0f0 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -299,7 +299,7 @@ where type SerializeStructVariant = ser::Impossible<(), Error>; unrepresentable!( - u8 u16 u32 u64 char unit unit_variant newtype_variant tuple + u8 u16 u32 u64 char unit newtype_variant tuple tuple_variant struct_variant ); @@ -343,6 +343,16 @@ where raw::write_bare_string(&mut self.outer.writer, value).map_err(From::from) } + #[inline] + fn serialize_unit_variant( + self, + _name: &'static str, + _variant_index: u32, + variant: &'static str, + ) -> Result<()> { + self.serialize_str(variant) + } + #[inline] fn serialize_bytes(self, _value: &[u8]) -> Result<()> { Err(Error::UnrepresentableType("u8")) @@ -496,7 +506,7 @@ where type SerializeStructVariant = ser::Impossible<(), Error>; unrepresentable!( - u8 u16 u32 u64 char unit unit_variant newtype_variant tuple + u8 u16 u32 u64 char unit newtype_variant tuple tuple_variant struct_variant ); @@ -540,6 +550,16 @@ where self.write_header(0x08) } + #[inline] + fn serialize_unit_variant( + self, + _name: &'static str, + _variant_index: u32, + variant: &'static str, + ) -> Result<()> { + self.serialize_str(variant) + } + #[inline] fn serialize_bytes(self, _value: &[u8]) -> Result<()> { Err(Error::UnrepresentableType("u8"))