Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Rewrite manual let-else #2366

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading