unwrap_or_else_error_handle
A simple Rust utility to handle errors by printing a custom message and exiting the program.
Usage
Add the function to your project:
use handle_error;
Suppose you have a function that returns a Result:
You can handle errors like this:
let value = might_fail
.unwrap_or_else;
If an error occurs, this will print:
An error occurred: Something went wrong
and exit the program with status code 1.
Example