From b591caff34bbdf1025a469527aead53e2f5c1bde Mon Sep 17 00:00:00 2001 From: Kornel Date: Mon, 9 Dec 2024 12:17:01 +0000 Subject: [PATCH] Clippy --- src/buffer.rs | 2 +- src/codecs/pnm/decoder.rs | 4 ++-- src/color.rs | 1 + src/flat.rs | 12 +++--------- src/imageops/sample.rs | 1 + 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/buffer.rs b/src/buffer.rs index 6a87ae9313..269d446fc8 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -801,7 +801,7 @@ where /// the bounds will not overflow. fn check_image_fits(width: u32, height: u32, len: usize) -> bool { let checked_len = Self::image_buffer_len(width, height); - checked_len.map_or(false, |min_len| min_len <= len) + checked_len.is_some_and(|min_len| min_len <= len) } fn image_buffer_len(width: u32, height: u32) -> Option { diff --git a/src/codecs/pnm/decoder.rs b/src/codecs/pnm/decoder.rs index 01c2c54b44..7b22f9c003 100644 --- a/src/codecs/pnm/decoder.rs +++ b/src/codecs/pnm/decoder.rs @@ -692,8 +692,8 @@ where let token = reader .bytes() - .skip_while(|v| v.as_ref().ok().map_or(false, is_separator)) - .take_while(|v| v.as_ref().ok().map_or(false, |c| !is_separator(c))) + .skip_while(|v| v.as_ref().ok().is_some_and(is_separator)) + .take_while(|v| v.as_ref().ok().is_some_and(|c| !is_separator(c))) .collect::, _>>()?; if !token.is_ascii() { diff --git a/src/color.rs b/src/color.rs index b3745d9b83..a83ca8c6b4 100644 --- a/src/color.rs +++ b/src/color.rs @@ -441,6 +441,7 @@ impl FromPrimitive for T { // 1.0 (white) was picked as firefox and chrome choose to map NaN to that. #[inline] fn normalize_float(float: f32, max: f32) -> f32 { + #[allow(clippy::neg_cmp_op_on_partial_ord)] let clamped = if !(float < 1.0) { 1.0 } else { float.max(0.0) }; (clamped * max).round() } diff --git a/src/flat.rs b/src/flat.rs index 08f82475b9..a67dc9ab2f 100644 --- a/src/flat.rs +++ b/src/flat.rs @@ -282,7 +282,7 @@ impl SampleLayout { /// Check if a buffer of length `len` is large enough. #[must_use] pub fn fits(&self, len: usize) -> bool { - self.min_length().map_or(false, |min| len >= min) + self.min_length().is_some_and(|min| len >= min) } /// The extents of this array, in order of increasing strides. @@ -747,10 +747,7 @@ impl FlatSamples { where Buffer: AsRef<[T]>, { - let min_length = match self.min_length() { - None => return None, - Some(index) => index, - }; + let min_length = self.min_length()?; let slice = self.samples.as_ref(); if slice.len() < min_length { @@ -765,10 +762,7 @@ impl FlatSamples { where Buffer: AsMut<[T]>, { - let min_length = match self.min_length() { - None => return None, - Some(index) => index, - }; + let min_length = self.min_length()?; let slice = self.samples.as_mut(); if slice.len() < min_length { diff --git a/src/imageops/sample.rs b/src/imageops/sample.rs index 1f6ce53a77..fa8043a20e 100644 --- a/src/imageops/sample.rs +++ b/src/imageops/sample.rs @@ -870,6 +870,7 @@ where let max = S::DEFAULT_MAX_VALUE; let max: f32 = NumCast::from(max).unwrap(); + #[allow(clippy::redundant_guards)] let sum = match kernel.iter().fold(0.0, |s, &item| s + item) { x if x == 0.0 => 1.0, sum => sum,