I just learned about this convenient method provided by Result.
Compared to using unwrap_or_else, I don't need to explicitly call
std::process::exit() and compared to using ? I still get to control
the error string (to include the filename in it).
}
let config_path = std::path::Path::new(&args[1]);
- let config = config::load_config(config_path).unwrap_or_else(|e| {
- eprintln!("Error loading config file {}: {}", args[1], e);
- std::process::exit(1);
- });
+ let config = config::load_config(config_path)
+ .expect(format!("Error loading config file {}", args[1]).as_str());
eprintln!("Race: {}", config.name);