For context, this is part of a very bare-bones GUI library. I would ideally want to be able to write something like this:
impl Widget for MyWidget {
fn get_drop_target(&self, pos: Vec2D) -> Option<DropTarget> {
self.get_drop_target_in_children(pos)?;
Some(self.make_drop_target())
}
}
The idea being that MyWidget is some kind of parent or layout that should check if its children have some kind of drop target available and return that if possible, otherwise return its own drop target. At the moment the behavior of ? makes it so that None is returned when encountered but if Some is encountered, execution continues. Is there an easy way to get the opposite of this behavior without using a whole if let statement? In this example it wouldn't be so bad but I have a couple widgets which have more custom behavior that requires calling methods on individual children, it would be really nice to be able to write something like:
impl Widget for Complicated {
fn get_drop_target(&self) -> Option<DropTarget> {
self.child1.get_drop_target()?;
if condition {
self.child2.get_drop_target()?;
}
self.child3.get_drop_target()?;
None
}
}