I have a struct and receive a reference to it in a function. I'd like to iterate over the field and if it is is None
it should behave as if the Vec
is empty. The best I can think of is
struct A {
m: Option<Vec<_>>,
}
fn example(a: &A) {
let v = vec![];
a.m.as_ref().unwrap_or_else(|| &v).iter()
}
I don't like declaring an outside vector just to have it exist outside of unwrap_or_else
.
Is there a more elegant solution?