I know some of my programs used to have lines with just x.unwrap().unwrap().unwrap() or whatever, which is not pretty.
That goes away with experience, though. At least, I can’t think of a reason why you’d nest three Results or Options. Normally, you would collate them right away.
The most you see in the wild is something like Result<Option<_>> to express that a check can fail, but even if it doesn’t, then a valid result can still be that there is nothing there.
If you don’t care that your program crashes (like .unwrap() does), then anyhow is the error handling library of choice. With it, you can just write a ? in place of an .unwrap() for practically any error type. And well, it automatically combines the errors, so you won’t be writing ??? either.
That goes away with experience, though. At least, I can’t think of a reason why you’d nest three Results or Options. Normally, you would collate them right away.
The most you see in the wild is something like
Result<Option<_>>to express that a check can fail, but even if it doesn’t, then a valid result can still be that there is nothing there.If you don’t care that your program crashes (like
.unwrap()does), thenanyhowis the error handling library of choice. With it, you can just write a?in place of an.unwrap()for practically any error type. And well, it automatically combines the errors, so you won’t be writing???either.