summaryrefslogtreecommitdiff
path: root/rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs
blob: a166fa231bacdd29a87c5985b34e03e88549623a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use std::{env, process};

use minigrep::Config;

fn main() {
    // args() return iterator
    // collect() extract iterator to collection we defined for args
    let args: Vec<String> = env::args().collect();

    let config = Config::build(&args).unwrap_or_else(|err| {
        eprintln!("Problem parsing arguments: {err}");
        process::exit(1);
    });

    // we only care about error code since ok will return ()
    // so `if let` is a ideal solution
    if let Err(e) = minigrep::run(config) {
        eprintln!("Application error: {e}");
        process::exit(1);
    }
}