Don't panic on Err Result
fn main() {
let error: Result<(), &str> = Err("error"); // Error
// Show error instead of panic
match error {
Ok(_) => println!("Ok"),
Err(e) => println!("Error: {}", e),
}
println!("Still running 🍕");
// Output:
// Error: error
// Still running 🍕
}
Here is what the above code is doing:
1. The function returns a Result<T, E> type. The Ok(T) value holds a T value, and the Err(E) value holds an E value.
2. The match expression is used to decide what to do based on the Result value. In this case,