make miniconf serialization and deserialization obey limits

This commit is contained in:
Max Känner 2024-08-03 13:16:40 +02:00
parent 9fb96bd2c3
commit 09043598ba

View File

@ -467,7 +467,7 @@ fn generate_tree_serialize(ident: &Ident, consts: &[Ident]) -> TokenStream2 {
let matches = consts.iter().enumerate().map(|(i, ident)| {
let index = i + 1;
quote! {
#index => ::miniconf::Serialize::serialize(&Self::#ident, ser).map_err(|err| ::miniconf::Error::Inner(0, err))?,
#index => Self::#ident.serialize(ser).map_err(|err| ::miniconf::Error::Inner(0, err))?,
}
});
quote! {
@ -483,7 +483,7 @@ fn generate_tree_serialize(ident: &Ident, consts: &[Ident]) -> TokenStream2 {
{
let ::core::result::Result::Ok(key) = keys.next::<Self>() else {
return ::miniconf::Error::increment_result({
::miniconf::Serialize::serialize(&self.0, ser).map_err(|err| ::miniconf::Error::Inner(0, err))?;
self.serialize(ser).map_err(|err| ::miniconf::Error::Inner(0, err))?;
::core::result::Result::Ok(0)
});
};
@ -493,7 +493,7 @@ fn generate_tree_serialize(ident: &Ident, consts: &[Ident]) -> TokenStream2 {
}
::miniconf::Error::increment_result({
match index {
0 => ::miniconf::Serialize::serialize(&self.0, ser).map_err(|err| ::miniconf::Error::Inner(0, err))?,
0 => self.serialize(ser).map_err(|err| ::miniconf::Error::Inner(0, err))?,
#(#matches)*
_ => unreachable!(),
};
@ -517,7 +517,7 @@ fn generate_tree_deserialize(ident: &Ident, num_keys: usize) -> TokenStream2 {
D: ::serde::Deserializer<'de>,
{
let ::core::result::Result::Ok(key) = keys.next::<Self>() else {
self.0 = ::miniconf::Deserialize::deserialize(de).map_err(|err| ::miniconf::Error::Inner(0, err))?;
*self = Self::deserialize(de).map_err(|err| ::miniconf::Error::Inner(0, err))?;
return ::core::result::Result::Ok(0);
};
let index = ::miniconf::Key::find::<Self>(&key).ok_or(::miniconf::Traversal::NotFound(1))?;
@ -526,7 +526,7 @@ fn generate_tree_deserialize(ident: &Ident, num_keys: usize) -> TokenStream2 {
}
match index {
0 => ::miniconf::Error::increment_result((||{
self.0 = ::miniconf::Deserialize::deserialize(de).map_err(|err| ::miniconf::Error::Inner(0, err))?;
*self = Self::deserialize(de).map_err(|err| ::miniconf::Error::Inner(0, err))?;
Ok(0)
})()),
1..=#num_keys => ::core::result::Result::Err(::miniconf::Traversal::Absent(0))?,