Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Dec 9, 2024
1 parent 7495e4b commit b591caf
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize> {
Expand Down
4 changes: 2 additions & 2 deletions src/codecs/pnm/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Result<Vec<u8>, _>>()?;

if !token.is_ascii() {
Expand Down
1 change: 1 addition & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ impl<T: Primitive> FromPrimitive<T> 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()
}
Expand Down
12 changes: 3 additions & 9 deletions src/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -747,10 +747,7 @@ impl<Buffer> FlatSamples<Buffer> {
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 {
Expand All @@ -765,10 +762,7 @@ impl<Buffer> FlatSamples<Buffer> {
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 {
Expand Down
1 change: 1 addition & 0 deletions src/imageops/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b591caf

Please sign in to comment.