From e5b648c01829bc01c6e3b1381c2499b9ad8e3043 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Tue, 10 Mar 2026 07:56:54 -0700 Subject: [PATCH] Use expect instead of unwrap_or_else 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). --- src/main.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index ecb0dcd..657e481 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,10 +14,8 @@ async fn main() -> Result<(), Box> { } 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); -- 2.45.2