Feat: Use unwrapping for error handling.
This commit is contained in:
+10
-7
@@ -10,17 +10,20 @@ struct Cli {
|
||||
fn main() {
|
||||
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.");
|
||||
|
||||
let result = std::fs::read_to_string("test.txt");
|
||||
match result {
|
||||
let result = std::fs::read_to_string(&args.path);
|
||||
let content = match result {
|
||||
Ok(content) => {
|
||||
println!("File content: {}", content);
|
||||
}
|
||||
content
|
||||
},
|
||||
Err(error) => {
|
||||
println!("Oh no error: {}", error);
|
||||
}
|
||||
panic!("Oh no error: {}", error);
|
||||
}
|
||||
};
|
||||
|
||||
// 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) {
|
||||
|
||||
Reference in New Issue
Block a user