Remove an unwrap
This commit is contained in:
parent
ef918dc724
commit
5962b13d05
1 changed files with 7 additions and 5 deletions
|
|
@ -295,6 +295,8 @@ struct Language {
|
|||
translation: Vec<String>,
|
||||
}
|
||||
|
||||
const UNABLE_TO_FIND_TRANSLATION_MESSAGE: &str = "Unable to find translation";
|
||||
|
||||
impl Language {
|
||||
pub fn from_stored_language(stored_language: StoredLanguage) -> Self {
|
||||
Self {
|
||||
|
|
@ -317,11 +319,11 @@ impl Language {
|
|||
{
|
||||
let sentence_cloned: Sentence = sentence.borrow().clone();
|
||||
|
||||
let text: &str = self
|
||||
.translation
|
||||
.get(sentence_cloned as usize)
|
||||
.unwrap()
|
||||
.as_ref();
|
||||
let text: &str = match self.translation.get(sentence_cloned as usize) {
|
||||
None => UNABLE_TO_FIND_TRANSLATION_MESSAGE,
|
||||
Some(text) => text,
|
||||
};
|
||||
|
||||
if text.is_empty() && self.code != DEFAULT_LANGUAGE_CODE {
|
||||
return get_language_translation(DEFAULT_LANGUAGE_CODE).get(sentence);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue