learning-rust/learning-rust.github.io

The unwrap_or* Error Handling Examples Need Improvement

SJonesy opened this issue · 0 comments

This page is the first or second google result for "rust unwrap_or_else example": https://learning-rust.github.io/docs/e4.unwrap_and_expect.html#unwrap-or-unwrap-or-default-and-unwrap-or-else

It takes longer than should be necessary to look at this pile of asserts and 1-2 character variable names and figure out the meaning. Having real examples would help a lot. The closure definitions in the unwrap_or_else example are particularly unhelpful as they don't include passing parameters to the closure, they're so short it makes it hard to think of them as anonymous functions, and they also aren't written in-line which is how they'll often be used.

Something like this is considerably more useful: https://gist.github.com/csknk/68b3d87bc76ce8c3431145fc0cc2fd3d