From 54cd8656ef10cf6553c506a6ee8d082331511080 Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Fri, 12 Apr 2019 22:24:13 +0100 Subject: [PATCH] Remove unwrap on canonicalize result --- src/main.rs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5e0b658689..01618b715f 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)); }