refactor: replace map_or(false, ...) with is_some_and(...)

This commit is contained in:
sxyazi 2023-10-01 15:47:39 +08:00
parent 73b9c62944
commit e5340a2beb
No known key found for this signature in database
4 changed files with 7 additions and 7 deletions

View File

@ -25,8 +25,8 @@ impl Open {
{ {
self.rules.iter().find_map(|rule| { self.rules.iter().find_map(|rule| {
let is_folder = Some(mime.as_ref() == MIME_DIR); let is_folder = Some(mime.as_ref() == MIME_DIR);
if rule.mime.as_ref().map_or(false, |m| m.matches(&mime)) if rule.mime.as_ref().is_some_and(|m| m.matches(&mime))
|| rule.name.as_ref().map_or(false, |n| n.match_path(&path, is_folder)) || rule.name.as_ref().is_some_and(|n| n.match_path(&path, is_folder))
{ {
let openers = rule let openers = rule
.use_ .use_

View File

@ -30,7 +30,7 @@ impl Pattern {
} else { } else {
path.file_name().and_then(|n| n.to_str()).or_else(|| path.to_str()) 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))
} }
} }

View File

@ -13,11 +13,11 @@ pub struct Filetype {
impl Filetype { impl Filetype {
pub fn matches(&self, path: &Path, mime: Option<impl AsRef<str>>, is_dir: bool) -> bool { pub fn matches(&self, path: &Path, mime: Option<impl AsRef<str>>, 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; return true;
} }
if let Some(mime) = mime { 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 false
} }

View File

@ -367,8 +367,8 @@ impl Manager {
false false
}; };
b |= self.active_mut().parent.as_mut().map_or(false, |p| p.hover(&cwd)); b |= self.active_mut().parent.as_mut().is_some_and(|p| p.hover(&cwd));
b |= hovered.as_ref().map_or(false, |h| self.current_mut().hover(h)); b |= hovered.as_ref().is_some_and(|h| self.current_mut().hover(h));
if hovered.as_ref() != self.hovered().map(|h| h.url()) { if hovered.as_ref() != self.hovered().map(|h| h.url()) {
emit!(Hover); emit!(Hover);