Is it possible to deserialize it in such a way that if a value is not provided for an entry, it would look up the value from a different "default" entry?
For example, suppose I have a struct like this:
#[derive(Deserialize, Serialize)]
struct Entry {
reticulate_splines: bool,
integrate_curves: bool,
align_covariance_matrices: bool,
chlorinate_threadpool: bool,
}
#[derive(Deserialize, Serialize)]
struct Config {
defaults: Entry,
#[serde(rename = "entry")]
entries: HashMap<String, Entry>,
}
I want to deserialize a config like the one below, where it would load the values defined in entries, and if missing, look up in "defaults", and fail if it's not in either.
[defaults]
integrate_curves = false
align_covariance_matrices = false
chlorinate_threadpool = true
[entry.Foo]
reticulate_splines = true
[entry.Bar]
reticulate_splines = false
chlorinate_threadpool = false
Is it possible? How would I go about doing it?
One way is to make all fields optional and manually merge after deserializing, but that's annoying.
I'm guessing it should be possible to implement a custom Deserialize for Config but I'm a bit lost on how to do it.