Feat: Use unwrapping for error handling.

This commit is contained in:
Ian Rettig
2025-06-06 16:55:57 -04:00
parent a663f2b4d8
commit 3ff1454fb6
+10 -7
View File
@@ -10,17 +10,20 @@ struct Cli {
fn main() { fn main() {
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.");
let result = std::fs::read_to_string("test.txt"); let result = std::fs::read_to_string(&args.path);
match result { let content = match result {
Ok(content) => { Ok(content) => {
println!("File content: {}", content); content
} },
Err(error) => { 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() { for line in content.lines() {
if line.contains(&args.pattern) { if line.contains(&args.pattern) {