Skip to content

Commit

Permalink
Allow empty structs
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Jan 28, 2025
1 parent f0c4479 commit 6a86b8c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 6 additions & 0 deletions merde/examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ struct Person<'s> {
merde::derive! {
impl (Serialize, Deserialize) for struct Person<'s> { name, age, address }
}

struct Empty {}

merde::derive! {
impl (Serialize, Deserialize) for struct Empty {}
}
8 changes: 4 additions & 4 deletions merde/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ macro_rules! impl_deserialize {

$(
let mut $field = $crate::none_of(|i: $struct_name| i.$field);
)+
)*

loop {
match __de.next().await? {
Expand Down Expand Up @@ -96,7 +96,7 @@ macro_rules! impl_deserialize {
__opinions.default_field_value(stringify!($field), __slot);
}
$crate::Deserialize::from_option($field, stringify!($field).into())?
},)+
},)*
})
}
}
Expand Down Expand Up @@ -514,7 +514,7 @@ macro_rules! impl_serialize {
$(
serializer.write($crate::Event::Str($crate::CowStr::Borrowed(stringify!($field)))).await?;
self.$field.serialize(serializer).await?;
)+
)*
serializer.write($crate::Event::MapEnd).await
}
}
Expand Down Expand Up @@ -545,7 +545,7 @@ macro_rules! impl_serialize {
serializer.write($crate::Event::Str($crate::CowStr::Borrowed($variant_str))).await?;
value.serialize(serializer).await?;
}
)+
)*
}

serializer.write($crate::Event::MapEnd).await
Expand Down

0 comments on commit 6a86b8c

Please sign in to comment.