diff --git a/src/serialize/per_type/datetime.rs b/src/serialize/per_type/datetime.rs index ae5fb35b..951398e7 100644 --- a/src/serialize/per_type/datetime.rs +++ b/src/serialize/per_type/datetime.rs @@ -73,7 +73,7 @@ impl Serialize for Date { { let mut buf = DateTimeBuffer::new(); self.write_buf(&mut buf); - serializer.serialize_str(str_from_slice!(buf.as_ptr(), buf.len())) + serializer.serialize_unit_struct(str_from_slice!(buf.as_ptr(), buf.len())) } } @@ -124,7 +124,7 @@ impl Serialize for Time { if self.write_buf(&mut buf).is_err() { err!(SerializeError::DatetimeLibraryUnsupported) }; - serializer.serialize_str(str_from_slice!(buf.as_ptr(), buf.len())) + serializer.serialize_unit_struct(str_from_slice!(buf.as_ptr(), buf.len())) } } @@ -243,6 +243,6 @@ impl Serialize for DateTime { if self.write_buf(&mut buf, self.opts).is_err() { err!(SerializeError::DatetimeLibraryUnsupported) } - serializer.serialize_str(str_from_slice!(buf.as_ptr(), buf.len())) + serializer.serialize_unit_struct(str_from_slice!(buf.as_ptr(), buf.len())) } } diff --git a/src/serialize/per_type/uuid.rs b/src/serialize/per_type/uuid.rs index ff02fc10..83cbbed9 100644 --- a/src/serialize/per_type/uuid.rs +++ b/src/serialize/per_type/uuid.rs @@ -60,6 +60,6 @@ impl Serialize for UUID { { let mut buf = arrayvec::ArrayVec::::new(); self.write_buf(&mut buf); - serializer.serialize_str(str_from_slice!(buf.as_ptr(), buf.len())) + serializer.serialize_unit_struct(str_from_slice!(buf.as_ptr(), buf.len())) } } diff --git a/src/serialize/writer/json.rs b/src/serialize/writer/json.rs index c6a51056..9b60e891 100644 --- a/src/serialize/writer/json.rs +++ b/src/serialize/writer/json.rs @@ -166,8 +166,18 @@ where .map_err(Error::io) } - fn serialize_unit_struct(self, _name: &'static str) -> Result<()> { - unreachable!(); + #[inline(always)] + fn serialize_unit_struct(self, name: &'static str) -> Result<()> { + debug_assert!(name.len() <= 36); + reserve_minimum!(self.writer); + unsafe { + self.writer.write_reserved_punctuation(b'"').unwrap(); + self.writer + .write_reserved_fragment(name.as_bytes()) + .unwrap(); + self.writer.write_reserved_punctuation(b'"').unwrap(); + } + Ok(()) } fn serialize_unit_variant(