Hi! In rust-analyzer, I have a bunch of code which returns
Result<T, Canceled>. Here’s an example: https://github.com/rust-analyzer/rust-analyzer/blob/d1b993c0aacb2a29fc87283a8b35fe1b4a542459/crates/ra_analysis/src/imp.rs#L281-L285
Cancelable means that the operation can be canceled at any time, and
Option is the usual “no reasonable value here”.
Such signatures are a pain to work with, because
? does not work with nested options. It is especially visible when you convert an
Option returning function into a
Cancelable<Option> returning function: all those sweet
? have to be converted to the
What are the practical approaches to deal with this problem in stable Rust (1.31.0 would also work)? Is the
xtry! macro the best we can do?
Ideally, I’d love to have some
.lift extension function on optionals which allows me to apply
?, but that seems impossible:
? can return only the
Err value, and I need to return an
An additional property of my situation is that I inspect (“handle”)
None values pretty regularly, but I never inspect the
Err(Canceled) value, I always propagate it upwards.