Skip to content

Commit

Permalink
refactor: Rewrite manual let-else
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Oct 26, 2024
1 parent 7a0a638 commit 187434a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
23 changes: 10 additions & 13 deletions src/codecs/gif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,19 +308,16 @@ impl<R: Read> Iterator for GifFrameIterator<R> {
// correct storage requirement if the result does not fit in `usize`.
// on the other hand, `ImageBuffer::from_raw` detects overflow and
// reports by returning `None`.
let mut frame_buffer = match ImageBuffer::from_raw(frame.width, frame.height, vec) {
Some(frame_buffer) => frame_buffer,
None => {
return Some(Err(ImageError::Unsupported(
UnsupportedError::from_format_and_kind(
ImageFormat::Gif.into(),
UnsupportedErrorKind::GenericFeature(format!(
"Image dimensions ({}, {}) are too large",
frame.width, frame.height
)),
),
)))
}
let Some(mut frame_buffer) = ImageBuffer::from_raw(frame.width, frame.height, vec) else {
return Some(Err(ImageError::Unsupported(
UnsupportedError::from_format_and_kind(
ImageFormat::Gif.into(),
UnsupportedErrorKind::GenericFeature(format!(
"Image dimensions ({}, {}) are too large",
frame.width, frame.height
)),
),
)));
};

// blend the current frame with the non-disposed frame, then update
Expand Down
17 changes: 7 additions & 10 deletions src/codecs/pnm/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,17 +540,14 @@ trait HeaderReader: Read {
}
}

let (h, w, d, m) = match (height, width, depth, maxval) {
(Some(h), Some(w), Some(d), Some(m)) => (h, w, d, m),
_ => {
return Err(DecoderError::HeaderLineMissing {
height,
width,
depth,
maxval,
}
.into())
let (Some(h), Some(w), Some(d), Some(m)) = (height, width, depth, maxval) else {
return Err(DecoderError::HeaderLineMissing {
height,
width,
depth,
maxval,
}
.into());
};

let tupltype = match tupltype {
Expand Down
5 changes: 2 additions & 3 deletions src/flat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,8 @@ impl SampleLayout {
let idx_x = x.checked_mul(self.width_stride);
let idx_y = y.checked_mul(self.height_stride);

let (idx_c, idx_x, idx_y) = match (idx_c, idx_x, idx_y) {
(Some(idx_c), Some(idx_x), Some(idx_y)) => (idx_c, idx_x, idx_y),
_ => return None,
let (Some(idx_c), Some(idx_x), Some(idx_y)) = (idx_c, idx_x, idx_y) else {
return None;
};

Some(0usize)
Expand Down
5 changes: 2 additions & 3 deletions tests/reference_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,8 @@ fn check_references() {
}
}

let test_img = match test_img.as_ref() {
Some(img) => img,
None => return,
let Some(test_img) = test_img.as_ref() else {
return;
};

let test_crc_actual = {
Expand Down

0 comments on commit 187434a

Please sign in to comment.