Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for unit_variant #62

Merged
merged 1 commit into from
Apr 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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