From: Carl Worth Date: Tue, 10 Mar 2026 00:04:39 +0000 (-0700) Subject: Switch from hello world to a program that prints a usage string X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=dda4d791f07485f7e71e3f2197abdba3cce5493c;p=rust-learning Switch from hello world to a program that prints a usage string OK, so it's not much more than "hello, world", but it just show how to use std::env as well as Vec 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). So, there's quite a bit of rust here, even for just a tiny block of code. --- diff --git a/src/main.rs b/src/main.rs index e7a11a9..34e2214 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,7 @@ fn main() { - println!("Hello, world!"); + let args: Vec = std::env::args().collect(); + if args.len() < 2 { + eprintln!("Usage: {} ", args[0]); + std::process::exit(1); + } }