I have an Option that contains some JSON. If it is Some, the inner JSON must be converted, but if it is None, it must remain None.
This is how I have this implemented currently:
struct One;
struct Other;
impl One {
pub fn convert(&self) -> Other {
Other {}
}
}
fn example(attr: Option<One>) -> Option<Other> {
match attr {
Some(attr) => Some(attr.convert()),
None => None,
}
}
I'm new to Rust and don't fully get the intricacies of when to use match, if let or when to use the ? operator.
Is my implementation idiomatic Rust? It seems rather verbose to me, and looks like a pattern that will occur all over the place, so I can imagine this can be handled far more concise; is that so?