add dese default_for_null (#860)
This commit is contained in:
parent
8d0d5a2d9a
commit
0526e920eb
|
@ -1697,7 +1697,7 @@ pub struct Ewasm {
|
||||||
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
#[derive(Clone, Debug, Default, Serialize, Deserialize, Eq, PartialEq)]
|
||||||
pub struct StorageLayout {
|
pub struct StorageLayout {
|
||||||
pub storage: Vec<Storage>,
|
pub storage: Vec<Storage>,
|
||||||
#[serde(default)]
|
#[serde(default, deserialize_with = "default_for_null")]
|
||||||
pub types: BTreeMap<String, StorageType>,
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in New Issue