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 🍕
}
BETA Snippet explanation automatically generated by OpenAI:

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,

Snippet By Posandu Mapa

·

Created September 12th, 2022

·

Report Snippet