1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use std::{env, error::Error};

pub struct Config {
    query: String,
    content: String,
}
///Config builder, taking command line arguments and generating a Config struct instace.
pub fn config_build(mut args: env::Args) -> Result<Config, Box<dyn Error>> {
    args.next();

    let query = args.next().ok_or_else(|| "no query".to_string())?;
    let content = args.next().ok_or_else(|| "No content".to_string())?;

    Ok(Config { query, content })
}

pub fn search<'a>(config: &'a Config) -> Vec<&'a str> {
    config
        .content
        .lines()
        .filter(|line| line.contains(&config.query))
        .collect()
}