Skip to content

Commit

Permalink
Replace map_or(false, ..) uses with is_some_and and is_ok_and (#…
Browse files Browse the repository at this point in the history
…4703)

## Summary

Looks like there isn't a clippy lint for this yet.
  • Loading branch information
ibraheemdev authored Jul 1, 2024
1 parent 8a2af8b commit be2a67c
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion crates/requirements-txt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ fn calculate_row_column(content: &str, position: usize) -> (usize, usize) {
// If the next character is a newline, skip it.
if chars
.peek()
.map_or(false, |&(_, next_char)| next_char == '\n')
.is_some_and(|&(_, next_char)| next_char == '\n')
{
chars.next();
}
Expand Down
8 changes: 4 additions & 4 deletions crates/uv-client/src/httpcache/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> CacheControlPa
)
}
let mut end = 0;
while self.cur.get(end).copied().map_or(false, is_token_byte) {
while self.cur.get(end).copied().is_some_and(is_token_byte) {
end += 1;
}
if end == 0 {
Expand All @@ -240,7 +240,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> CacheControlPa
///
/// [RFC 9111 Appendix A]: https://www.rfc-editor.org/rfc/rfc9111.html#name-collected-abnf
fn maybe_parse_equals(&mut self) -> bool {
if self.cur.first().map_or(false, |&byte| byte == b'=') {
if self.cur.first().is_some_and(|&byte| byte == b'=') {
self.cur = &self.cur[1..];
true
} else {
Expand Down Expand Up @@ -322,7 +322,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> CacheControlPa
///
/// [RFC 9111 Appendix A]: https://www.rfc-editor.org/rfc/rfc9111.html#name-collected-abnf
fn maybe_parse_directive_delimiter(&mut self) -> bool {
if self.cur.first().map_or(false, |&byte| byte == b',') {
if self.cur.first().is_some_and(|&byte| byte == b',') {
self.cur = &self.cur[1..];
true
} else {
Expand All @@ -336,7 +336,7 @@ impl<'b, B: 'b + ?Sized + AsRef<[u8]>, I: Iterator<Item = &'b B>> CacheControlPa
///
/// [RFC 9111 Appendix A]: https://www.rfc-editor.org/rfc/rfc9111.html#name-collected-abnf
fn skip_whitespace(&mut self) {
while self.cur.first().map_or(false, u8::is_ascii_whitespace) {
while self.cur.first().is_some_and(u8::is_ascii_whitespace) {
self.cur = &self.cur[1..];
}
}
Expand Down
14 changes: 3 additions & 11 deletions crates/uv-fs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,7 @@ pub fn directories(path: impl AsRef<Path>) -> impl Iterator<Item = PathBuf> {
None
}
})
.filter(|entry| {
entry
.file_type()
.map_or(false, |file_type| file_type.is_dir())
})
.filter(|entry| entry.file_type().is_ok_and(|file_type| file_type.is_dir()))
.map(|entry| entry.path())
}

Expand All @@ -228,7 +224,7 @@ pub fn symlinks(path: impl AsRef<Path>) -> impl Iterator<Item = PathBuf> {
.filter(|entry| {
entry
.file_type()
.map_or(false, |file_type| file_type.is_symlink())
.is_ok_and(|file_type| file_type.is_symlink())
})
.map(|entry| entry.path())
}
Expand All @@ -249,11 +245,7 @@ pub fn files(path: impl AsRef<Path>) -> impl Iterator<Item = PathBuf> {
None
}
})
.filter(|entry| {
entry
.file_type()
.map_or(false, |file_type| file_type.is_file())
})
.filter(|entry| entry.file_type().is_ok_and(|file_type| file_type.is_file()))
.map(|entry| entry.path())
}

Expand Down
7 changes: 4 additions & 3 deletions crates/uv-installer/src/site_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ impl SitePackages {
.filter_map(|read_dir| match read_dir {
Ok(entry) => match entry.file_type() {
Ok(file_type) => (file_type.is_dir()
|| entry.path().extension().map_or(false, |ext| {
ext == "egg-link" || ext == "egg-info"
}))
|| entry
.path()
.extension()
.is_some_and(|ext| ext == "egg-link" || ext == "egg-info"))
.then_some(Ok(entry.path())),
Err(err) => Some(Err(err)),
},
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-toolchain/src/managed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl InstalledToolchain {
ToolchainRequest::ExecutableName(name) => self
.executable()
.file_name()
.map_or(false, |filename| filename.to_string_lossy() == *name),
.is_some_and(|filename| filename.to_string_lossy() == *name),
ToolchainRequest::Implementation(implementation) => {
implementation == self.implementation()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/src/commands/project/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ impl From<ExternalCommand> for RunCommand {
let target_path = PathBuf::from(&target);
if target_path
.extension()
.map_or(false, |ext| ext.eq_ignore_ascii_case("py"))
.is_some_and(|ext| ext.eq_ignore_ascii_case("py"))
&& target_path.exists()
{
Self::Python(target_path, args.to_vec())
Expand Down

0 comments on commit be2a67c

Please sign in to comment.