Use Box<dyn Error> as the error type in your function's Result to handle multiple error types without defining a custom enum.
use std::error::Error;
use std::fs::File;
fn run() -> Result<(), Box<dyn Error>> {
let _greeting_file = File::open("hello.txt")?;
Ok(())
}
This pattern allows the ? operator to automatically convert any error implementing the Error trait into a Box<dyn Error>, simplifying error propagation in functions like run or main.