Skip to content

Commit

Permalink
Remove unwrap on system language parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
geom3trik committed Jul 20, 2022
1 parent 73a5fda commit ed840e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl Default for Environment {

impl Environment {
pub fn new() -> Self {
let locale = sys_locale::get_locale().map(|l| l.parse().unwrap()).unwrap_or_default();
let locale = sys_locale::get_locale().map(|l| l.parse().ok()).flatten().unwrap_or_default();

Self { locale, include_default_theme: true }
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub struct ResourceManager {

impl ResourceManager {
pub fn new() -> Self {
let locale = sys_locale::get_locale().map(|l| l.parse().unwrap()).unwrap_or_default();
let locale = sys_locale::get_locale().map(|l| l.parse().ok()).flatten().unwrap_or_default();

ResourceManager {
stylesheets: Vec::new(),
Expand All @@ -100,7 +100,8 @@ impl ResourceManager {
.filter(|&x| x != &LanguageIdentifier::default())
.collect::<Vec<_>>();
let locale = sys_locale::get_locale()
.map(|l| l.parse().unwrap())
.map(|l| l.parse().ok())
.flatten()
.unwrap_or_else(|| available.first().copied().cloned().unwrap_or_default());
let default = LanguageIdentifier::default();
let default_ref = &default; // ???
Expand Down

0 comments on commit ed840e9

Please sign in to comment.