Skip to content

Commit

Permalink
add support for unit_variant
Browse files Browse the repository at this point in the history
  • Loading branch information
Freax13 authored and atheriel committed Apr 19, 2021
1 parent dccdb76 commit 3e937ec
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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
);

Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit 3e937ec

Please sign in to comment.