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. `let error: Result<(), &str> = Err("error");`: This is a Result type. Result type is provided by the Rust compiler. It is a type that represents either success or failure. This is a common type you see in Rust code.
2. `

Snippet By Posandu Mapa

ยท

Created September 12th, 2022

ยท

Report Snippet