add dese default_for_null (#860)

This commit is contained in:
joshieDo 2022-02-04 10:09:53 +02:00 committed by GitHub
parent 8d0d5a2d9a
commit 0526e920eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -1697,7 +1697,7 @@ pub struct Ewasm {
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
pub struct StorageLayout {
pub storage: Vec<Storage>,
#[serde(default)]
#[serde(default, deserialize_with = "default_for_null")]
pub types: BTreeMap<String, StorageType>,
}
@ -1990,6 +1990,14 @@ where
}
}
fn default_for_null<'de, D, T>(deserializer: D) -> Result<T, D::Error>
where
D: Deserializer<'de>,
T: Deserialize<'de> + Default,
{
Ok(Option::<T>::deserialize(deserializer)?.unwrap_or_default())
}
#[cfg(test)]
mod tests {
use super::*;