How it works...
Thanks to Rust's ability to check panic results, we can verify the messages and the fact that the panic occurred. From step 2 to step 4, we are simply panicking using various (common) methods, such as unwrap() (https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap) or panic!() (https://doc.rust-lang.org/std/macro.panic.html). These methods return messages such as 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:347:21, or panicked at 'explicit panic', src/lib.rs:64:9, which are not easy to debug.
However, there is a variation of unwrap() called expect(), which takes a &str parameter as a simple message for users to debug the issue further. Steps 4 to 6 show how messages and return values are ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access