Defend unknown values

This commit is contained in:
Ferran Basora 2019-02-25 23:00:36 +00:00
parent 2c2d140796
commit 5a0226fc63
2 changed files with 4 additions and 0 deletions

View File

@ -60,6 +60,8 @@ impl<'a> Alphabet<'a> {
pub fn get_alphabet(alphabet_name: &str) -> Alphabet { pub fn get_alphabet(alphabet_name: &str) -> Alphabet {
let alphabets: HashMap<&str, &str> = ALPHABETS.iter().cloned().collect(); 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]) Alphabet::new(alphabets[alphabet_name])
} }

View File

@ -16,6 +16,8 @@ const COLORS: [(&'static str, Color); 9] = [
pub fn get_color(color_name: &str) -> Color { pub fn get_color(color_name: &str) -> Color {
let available_colors: HashMap<&str, Color> = COLORS.iter().cloned().collect(); 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] available_colors[&color_name]
} }