]> git.cworth.org Git - rust-learning/commitdiff
Switch from hello world to a program that prints a usage string
authorCarl Worth <cworth@cworth.org>
Tue, 10 Mar 2026 00:04:39 +0000 (17:04 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 12 Mar 2026 04:14:17 +0000 (21:14 -0700)
OK, so it's not much more than "hello, world", but it just show how to
use std::env as well as Vec<String> and even has an actual condition
in it! It's almost like real programming now.

Oh, and of course there's the collect() call which showcases both an
iterator and the magic of rust's type inference here (telling
collect() to return a Vec<string>). So, there's quite a bit of rust
here, even for just a tiny block of code.

src/main.rs

index e7a11a969c037e00a796aafeff6258501ec15e9a..34e221406f5945a61d91f978893b8cd04e5df073 100644 (file)
@@ -1,3 +1,7 @@
 fn main() {
-    println!("Hello, world!");
+    let args: Vec<String> = std::env::args().collect();
+    if args.len() < 2 {
+        eprintln!("Usage: {} <race-config.json>", args[0]);
+        std::process::exit(1);
+    }
 }