3 ms·
I rarely if ever use the question mark with 'Option' when working with rust, and it's been just fine. I do use it a lot with Result though. But if you have any
by swsieber 4y ago
I rarely if ever use the question mark with 'Option' when working with rust, and it's been just fine.
I do use it a lot with Result though. But if you have any question about the return type you could[1] just look at the return type for the current function you're in.
[1] I think there's a way to define custom types on nightly, and I wouldn't be surprised if it let you map custom types on Result/Option, but I don't actually know.
- ramranch 4y agoI am a fan of Rust, but I feel obligated to point out the return type of the current function does not provide any guarantees about the type which '?' was used on, even on stable. Since the generic requirement to use '?' with a return type of `Result<T,E>` is just `Into<E>`, you would still need to look at the called function since `From<E> for T` could be satisfied for (almost) any T.
- swsieber 4y agoAh, I did not realize that. Thanks for pointing that out!