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.
-fn main() {
+use std::error::Error;
+
+fn main() -> Result<(), Box<dyn Error>> {
let args: Vec<String> = std::env::args().collect();
if args.len() < 2 {
- eprintln!("Usage: {} <race-config.json>", args[0]);
- std::process::exit(1);
+ return Err(format!("Usage: {} <race-config.json>", args[0]).into());
}
+
+ Ok(())
}