Feat: return error in unwrap.
This commit is contained in:
+4
-5
@@ -7,7 +7,7 @@ struct Cli {
|
||||
path: std::path::PathBuf,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>>{
|
||||
let args = Cli::parse();
|
||||
|
||||
// let content = std::fs::read_to_string(&args.path).expect("Could not read file.");
|
||||
@@ -18,16 +18,15 @@ fn main() {
|
||||
content
|
||||
},
|
||||
Err(error) => {
|
||||
panic!("Oh no error: {}", error);
|
||||
return Err(error.into());
|
||||
}
|
||||
};
|
||||
|
||||
// can do the same with following
|
||||
// let content = std::fs::read_to_string(&args.path).unwrap();
|
||||
|
||||
for line in content.lines() {
|
||||
if line.contains(&args.pattern) {
|
||||
println!("{}", line)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user