mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00

This allows us to normalize bad data, and is the first step towards splitting note types into separate tables.
17 lines
570 B
Rust
17 lines
570 B
Rust
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
use serde::Deserialize as DeTrait;
|
|
pub(crate) use serde_aux::field_attributes::{
|
|
deserialize_bool_from_anything, deserialize_number_from_string,
|
|
};
|
|
use serde_json::Value;
|
|
|
|
pub(crate) fn default_on_invalid<'de, T, D>(deserializer: D) -> Result<T, D::Error>
|
|
where
|
|
T: Default + DeTrait<'de>,
|
|
D: serde::de::Deserializer<'de>,
|
|
{
|
|
let v: Value = DeTrait::deserialize(deserializer)?;
|
|
Ok(T::deserialize(v).unwrap_or_default())
|
|
}
|