From 5a0226fc638ca0bbadddb053ad335456f3a1a6b7 Mon Sep 17 00:00:00 2001 From: Ferran Basora Date: Mon, 25 Feb 2019 23:00:36 +0000 Subject: [PATCH] Defend unknown values --- src/alphabets.rs | 2 ++ src/colors.rs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/alphabets.rs b/src/alphabets.rs index 8f041d3..10dfdc0 100644 --- a/src/alphabets.rs +++ b/src/alphabets.rs @@ -60,6 +60,8 @@ impl<'a> Alphabet<'a> { pub fn get_alphabet(alphabet_name: &str) -> Alphabet { let alphabets: HashMap<&str, &str> = ALPHABETS.iter().cloned().collect(); + alphabets.get(alphabet_name).expect(format!("Unknown alphabet: {}", alphabet_name).as_str()); // FIXME + Alphabet::new(alphabets[alphabet_name]) } diff --git a/src/colors.rs b/src/colors.rs index 0713d1d..4424db2 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -16,6 +16,8 @@ const COLORS: [(&'static str, Color); 9] = [ pub fn get_color(color_name: &str) -> Color { let available_colors: HashMap<&str, Color> = COLORS.iter().cloned().collect(); + available_colors.get(color_name).expect(format!("Unknown color: {}", color_name).as_str()); // FIXME + available_colors[&color_name] }