Skip to content

Commit 3054e15

Browse files
authored
fix(derive): Support serialization of enums with no arms. (#113)
1 parent 7c0e7c4 commit 3054e15

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

xmlity-derive/src/ser/serialize/none.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ impl SerializeBuilder for DeriveEnum<'_> {
150150
});
151151
}
152152

153+
if variants.is_empty() {
154+
return Ok(parse_quote! {
155+
unreachable!("Enum {} has no variants", stringify!(#enum_ident))
156+
});
157+
}
158+
153159
let variants = variants
154160
.iter()
155161
.map::<Result<Arm, DeriveError>, _>(|variant| {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#[derive(
2+
::core::fmt::Debug,
3+
::xmlity::Serialize,
4+
::xmlity::Deserialize,
5+
::core::cmp::PartialEq,
6+
::core::clone::Clone,
7+
)]
8+
pub enum NamespaceList {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod combined;
22
pub mod empty;
33
pub mod empty_variant;
4+
pub mod enum_with_no_arm;
45
pub mod variant;
56
pub mod xml_value;

0 commit comments

Comments
 (0)