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()
}