From 45b4fb4058591995c405572f8921086b79325077 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Mon, 9 Mar 2026 18:52:58 -0700 Subject: [PATCH] Return an actual value from main This is a more idiomatic behavior from main, using a Result to return either the unit type (which will cause a return of 0) or else an Error (coerced from a string by using .into()). In that case, the program will print "Error: " and our error string before exiting with a value of 1. --- src/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 34e2214..404dde8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,10 @@ -fn main() { +use std::error::Error; + +fn main() -> Result<(), Box> { let args: Vec = std::env::args().collect(); if args.len() < 2 { - eprintln!("Usage: {} ", args[0]); - std::process::exit(1); + return Err(format!("Usage: {} ", args[0]).into()); } + + Ok(()) } -- 2.45.2