I'm trying out Rust at home and I wrote some code that looks like this.
let mut foo = ...; // foo: Option<T>
if let Some(ref mut f) = foo {
f.bar();
}
// [...some code here...]
if let Some(ref mut f) = foo {
f.baz();
}
I tried to replace the if-lets with foo?.bar();
and foo?.baz();
like I usually do in C# but then Rust correctly complains that the function doesn't return a Result
or a Option
or other type that implements Try
(of course it does, since ?
"short-circuits" the whole function).
Is there a macro or an operator that works similar to C# where it just ignores the rest of the expression like it were in a if-let?
Thanks.