Skip to content

Commit

Permalink
Remove unwrap on canonicalize result
Browse files Browse the repository at this point in the history
  • Loading branch information
cjpearce committed Apr 12, 2019
1 parent 6441251 commit 54cd865
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit 54cd865

Please sign in to comment.