Re:A half-hour to learn Rust
by jackric on Saturday January 02, 2021 @06:30AM
(#25612064)
I would suggest Option is the more semantic type to use for your situation - None indicating no valid solution on this path
[ Parent
| on HN ]
Re:A half-hour to learn Rust
by CJefferson on Saturday January 02, 2021 @10:23AM
(#25613385)
Oh, today I learned the ? operator works with Option as well as Result! I might try that out, thanks.
IIRC, it didn't work with Option in the past, so you might have been correct when your code was written. The ? operator came originally from the try!() macro, which was specific to Result; unlike the macro, it was designed to be extensible through the still-unstable std::ops::Try trait, but IIRC that trait was initially implemented only for Result, and only later was extended to Option and a couple of others.