Use the ? operator to immediately return the error from main() if a function call fails, or wrap the error handling logic in a separate function and return a Result.
use std::fs::File;
use std::io::Error;
fn main() -> Result<(), Error> {
let file = File::open("hello.txt")?;
Ok(())
}
Alternatively, use panic! to stop execution on unrecoverable errors:
fn main() {
let file = File::open("hello.txt").expect("Failed to open file");
}