10 pub fn new(args
: &[String
]) -> Result
<Config
, &str> {
12 return Err("not enough arguments");
15 let query
= args
[1].clone();
16 let filename
= args
[2].clone();
18 Ok(Config { query, filename }
)
23 pub fn run(config
: Config
) -> Result
<(), Box
<dyn Error
>> {
24 let contents
= fs
::read_to_string(config
.filename
)?
;
26 for line
in search(&config
.query
, &contents
) {
34 pub fn search
<'a
>(query
: &str, contents
: &'a
str) -> Vec
<&'a
str> {
35 let mut results
= Vec
::new();
37 for line
in contents
.lines() {
38 if line
.contains(query
) {
55 safe, fast, productive.
58 assert_eq
!(vec
!["safe, fast, productive."], search(query
, contents
));