~irimi1/learning-rust

eb12df69b15d44575765b28c99881df68757d1e3 — Manuel Groß 2 years ago 18836e7
minigrep: Make function a method of Config
1 files changed, 7 insertions(+), 5 deletions(-)

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

    let config = parse_config(&args);
    let config = Config::new(&args);

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


@@ 20,9 20,11 @@ struct Config {
    filename: String,
}

fn parse_config(args: &[String]) -> Config {
    let query = args[1].clone();
    let filename = args[2].clone();
impl Config {
    fn new(args: &[String]) -> Config {
        let query = args[1].clone();
        let filename = args[2].clone();

    Config { query, filename }
        Config { query, filename }
    }
}