Skip to content

Commit 8c867a0

Browse files
committed
Remove unwrap on canonicalize result
1 parent d01a71f commit 8c867a0

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/main.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,17 @@ fn main() {
6767
std::process::exit(1);
6868
});
6969

70-
let filepath = Path::new(filename).canonicalize().unwrap();
71-
let exercise = exercises
72-
.iter()
73-
.find(|e| filepath.ends_with(&e.path))
74-
.unwrap_or_else(|| {
75-
println!("No exercise found for your file name!");
76-
std::process::exit(1)
77-
});
70+
let matching_exercise = |e: &&Exercise| {
71+
Path::new(filename)
72+
.canonicalize()
73+
.map(|p| p.ends_with(&e.path))
74+
.unwrap_or(false)
75+
};
76+
77+
let exercise = exercises.iter().find(matching_exercise).unwrap_or_else(|| {
78+
println!("No exercise found for your file name!");
79+
std::process::exit(1)
80+
});
7881

7982
run(&exercise).unwrap_or_else(|_| std::process::exit(1));
8083
}

0 commit comments

Comments
 (0)