Get the latest tech news
Don't unwrap options: There are better ways (2024)
I noticed that handling the None variant of Option without falling back on unwrap() is a common papercut in Rust. More specifically, the problem arises when you want to return early from a function that retur…
It has been discussed a million times already, but, surprisingly, not even the Rust book mentions my favorite approach to handling that, and many forum posts are outdated. But what if the final return type of your function has to be a Result or if you want to convey more information about the missing value to the caller? However, you might not be able to change get_user() to return a Result for various reasons, for example, if it’s part of a library or if it’s used in many places or if other callers don’t treat the absence of a user as an error.
Or read this on Hacker News