From e5340a2bebe1cfc0151bcd630e5ad9a502519de7 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 1 Oct 2023 15:47:39 +0800 Subject: [PATCH] refactor: replace `map_or(false, ...)` with `is_some_and(...)` --- config/src/open/open.rs | 4 ++-- config/src/pattern.rs | 2 +- config/src/theme/filetype.rs | 4 ++-- core/src/manager/manager.rs | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/config/src/open/open.rs b/config/src/open/open.rs index 879b6b3b..1345492d 100644 --- a/config/src/open/open.rs +++ b/config/src/open/open.rs @@ -25,8 +25,8 @@ impl Open { { self.rules.iter().find_map(|rule| { let is_folder = Some(mime.as_ref() == MIME_DIR); - if rule.mime.as_ref().map_or(false, |m| m.matches(&mime)) - || rule.name.as_ref().map_or(false, |n| n.match_path(&path, is_folder)) + if rule.mime.as_ref().is_some_and(|m| m.matches(&mime)) + || rule.name.as_ref().is_some_and(|n| n.match_path(&path, is_folder)) { let openers = rule .use_ diff --git a/config/src/pattern.rs b/config/src/pattern.rs index 7a9d7c30..e4930dd9 100644 --- a/config/src/pattern.rs +++ b/config/src/pattern.rs @@ -30,7 +30,7 @@ impl Pattern { } else { path.file_name().and_then(|n| n.to_str()).or_else(|| path.to_str()) }; - is_folder.map_or(true, |f| f == self.is_folder) && s.map_or(false, |s| self.matches(s)) + is_folder.map_or(true, |f| f == self.is_folder) && s.is_some_and(|s| self.matches(s)) } } diff --git a/config/src/theme/filetype.rs b/config/src/theme/filetype.rs index cd39f948..b439821a 100644 --- a/config/src/theme/filetype.rs +++ b/config/src/theme/filetype.rs @@ -13,11 +13,11 @@ pub struct Filetype { impl Filetype { pub fn matches(&self, path: &Path, mime: Option>, is_dir: bool) -> bool { - if self.name.as_ref().map_or(false, |e| e.match_path(path, Some(is_dir))) { + if self.name.as_ref().is_some_and(|e| e.match_path(path, Some(is_dir))) { return true; } if let Some(mime) = mime { - return self.mime.as_ref().map_or(false, |m| m.matches(mime)); + return self.mime.as_ref().is_some_and(|m| m.matches(mime)); } false } diff --git a/core/src/manager/manager.rs b/core/src/manager/manager.rs index 7e80a303..4de2bf6c 100644 --- a/core/src/manager/manager.rs +++ b/core/src/manager/manager.rs @@ -367,8 +367,8 @@ impl Manager { false }; - b |= self.active_mut().parent.as_mut().map_or(false, |p| p.hover(&cwd)); - b |= hovered.as_ref().map_or(false, |h| self.current_mut().hover(h)); + b |= self.active_mut().parent.as_mut().is_some_and(|p| p.hover(&cwd)); + b |= hovered.as_ref().is_some_and(|h| self.current_mut().hover(h)); if hovered.as_ref() != self.hovered().map(|h| h.url()) { emit!(Hover);