summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorChris Pearce <christopher.james.pearce@gmail.com>2019-04-12 22:24:13 +0100
committerChris Pearce <christopher.james.pearce@gmail.com>2019-04-12 22:24:13 +0100
commit8c867a001a0d588b2aa367f89ae71f6fa548daa8 (patch)
tree3df264a2013e8d812656af1727b6cb7eefb2261b /src/main.rs
parentd01a71f7de15f34922dc2a14a00436f466b84e87 (diff)
Remove unwrap on canonicalize result
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/main.rs b/src/main.rs
index 5e0b658..01618b7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -67,14 +67,17 @@ fn main() {
std::process::exit(1);
});
- let filepath = Path::new(filename).canonicalize().unwrap();
- let exercise = exercises
- .iter()
- .find(|e| filepath.ends_with(&e.path))
- .unwrap_or_else(|| {
- println!("No exercise found for your file name!");
- std::process::exit(1)
- });
+ let matching_exercise = |e: &&Exercise| {
+ Path::new(filename)
+ .canonicalize()
+ .map(|p| p.ends_with(&e.path))
+ .unwrap_or(false)
+ };
+
+ let exercise = exercises.iter().find(matching_exercise).unwrap_or_else(|| {
+ println!("No exercise found for your file name!");
+ std::process::exit(1)
+ });
run(&exercise).unwrap_or_else(|_| std::process::exit(1));
}