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