diff --git a/src/filetypes.rs b/src/filetypes.rs index b900ece..c4e65fc 100644 --- a/src/filetypes.rs +++ b/src/filetypes.rs @@ -46,7 +46,7 @@ impl FileTypes { let code = Self::get_code(filetype); let result = mapping.insert(code, category.clone()); - if !result.is_none() { + if result.is_some() { return Err(VividError::DuplicateFileType(filetype.to_string())); } } else { diff --git a/src/main.rs b/src/main.rs index 9ae0c2e..68429a4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -92,7 +92,7 @@ fn run() -> Result<()> { let theme_name_env = env::var("VIVID_THEME").ok(); let theme_name = sub_matches .value_of("theme") - .or(theme_name_env.as_ref().map(String::as_str)) + .or_else(|| theme_name_env.as_ref().map(String::as_str)) .unwrap_or("molokai"); let theme_file = format!("{}.yml", theme_name); @@ -105,7 +105,7 @@ fn run() -> Result<()> { theme_path_system.push(theme_file); let theme_path = util::get_first_existing_path(&[&theme_path_user, &theme_path_system]) - .ok_or(VividError::CouldNotFindTheme(theme_name.to_string()))?; + .ok_or_else(|| VividError::CouldNotFindTheme(theme_name.to_string()))?; let theme = Theme::from_file(theme_path, color_mode)?; let mut filetypes_list = filetypes.mapping.keys().collect::>(); diff --git a/src/theme.rs b/src/theme.rs index 9c47cde..f504933 100644 --- a/src/theme.rs +++ b/src/theme.rs @@ -68,9 +68,9 @@ impl Theme { fn get_color(&self, color_str: &str) -> Result { self.colors .get(color_str) - .map(|c| c.clone()) - .or(Color::from_hex_str(color_str).ok()) - .ok_or(VividError::UnknownColor(color_str.to_string())) + .cloned() + .or_else(|| Color::from_hex_str(color_str).ok()) + .ok_or_else(|| VividError::UnknownColor(color_str.to_string())) } pub fn get_style(&self, category: CategoryRef) -> Result {