Unwraps

Rust allows you to unwrap Results and Options, at the cost of panicking if they are Err(_) or None respectively. This should be avoided in any production code, and either use expect() to add an information message or use error chaining with the ? operator, for example. You can also match them and control the error.

To avoid those unnecessary panics, you can use the result_unwrap_used, option_unwrap_used, option_map_unwrap_or_else, option_map_unwrap_or, and result_map_unwrap_or_else lints.

Get Rust High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.