11 let args
: Vec
<String
> = env
::args().collect();
13 let config
= Config
::new(&args
).unwrap_or_else(|err
| {
14 println
!("Problem parsing arguments: {}", err
);
19 println
!("Searching for {}", config
.query
);
20 println
!("In file {}", config
.filename
);
22 if let Err(e
) = run(config
) {
23 println
!("Application error: {}", e
);
30 fn run(config
: Config
) -> Result
<(), Box
<dyn Error
>> {
31 let contents
= fs
::read_to_string(config
.filename
)?
;
33 println
!("With text:\n{}", contents
);
44 fn new(args
: &[String
]) -> Result
<Config
, &str> {
46 return Err("not enough arguments");
49 let query
= args
[1].clone();
50 let filename
= args
[2].clone();
52 Ok(Config { query, filename }
)