Feat: Use unwrapping for error handling.
This commit is contained in:
+10
-7
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user