From ef73dc1db2f0389912e442b0f6cd5fa6712d4026 Mon Sep 17 00:00:00 2001 From: j-james Date: Tue, 15 Nov 2022 00:00:02 -0800 Subject: Add the I/O project from the Rust book --- minigrep/src/main.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 minigrep/src/main.rs (limited to 'minigrep/src/main.rs') diff --git a/minigrep/src/main.rs b/minigrep/src/main.rs new file mode 100644 index 0000000..5066347 --- /dev/null +++ b/minigrep/src/main.rs @@ -0,0 +1,23 @@ +use std::env; +use std::process; + +use minigrep::Config; + +fn main() { + let args: Vec = env::args().collect(); + // & is a reference, so we don't worry abt the borrow checker until args goes out of scope + let config = Config::new(&args).unwrap_or_else(|err| { + eprintln!("Problem parsing arguments: {}", err); + process::exit(1); + }); + + // println!("Searching for {}", config.query); + // println!("In file {}", config.filename); + + // passing a variable without an ampersand moves it + if let Err(e) = minigrep::run(config) { + // this syntax is a little bit weird - you're almost implicitly running run() + eprintln!("Application error: {}", e); + process::exit(1); + } +} -- cgit v1.2.3-70-g09d2