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>.
@mbrubeck Thanks for your anwser. I did see your answer in the link you'be been providing. But I don't want a default, rather call another method. The only thing is just replace the T::default by another call ?