Hi all,
I can't solve my problem.
I'm deserializing a YAML file to a struct. One of the YAML field is optional, and is usually mapped with an Option<T>
. Example:
struct YamlFile {
name: Option<String>,
}
But how to get rid of the Option
so that if the field is found in YAML, it is deserialized, and if not, a default method is called ? That way, the struct will boil down to:
struct YamlFile {
name: String,
}
I played with serde
attributes but I didn't succeed. What I achieved is to keep the Option
and call a default method to return Some(value)
.
I simplified here, but the field is not an Option<String>
but an Option<Large struct>
.
Thanks a lot for your hints.