- I have this code snippet:
pub struct Foo {
pub t: i32,
}
pub struct Bar {
pub x: Option<Foo>,
}
impl Bar {
pub fn test(&self) -> Option<i32> {
let y = &self.x?;
Some(y.t + 2)
}
}
-
The point here is not to call some function that does
( (A -> B), Option<A>) -> Option<B>
-
The point here is that I have an "&Option", and I want to use the
?
operator to extract a&A
(and short circuit exit if it's None). -
Why can't I do this?