~irimi1/learning-rust

7ad2157efa698b7f4b234fdb1851cc268961b650 — Manuel Groß 2 years ago 5f333e2
minigrep: Put argument parsing in separate function
1 files changed, 8 insertions(+), 2 deletions(-)

M projects/minigrep/src/main.rs
M projects/minigrep/src/main.rs => projects/minigrep/src/main.rs +8 -2
@@ 4,8 4,7 @@ use std::fs;
fn main() {
    let args: Vec<String> = env::args().collect();

    let query = &args[1];
    let filename = &args[2];
    let (query, filename) = parse_config(&args);

    println!("Searching for {}", query);
    println!("In file {}", filename);


@@ 15,3 14,10 @@ fn main() {

    println!("With text:\n{}", contents);
}

fn parse_config(args: &[String]) -> (&str, &str) {
    let query = &args[1];
    let filename = &args[2];

    (query, filename)
}