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

Clippy fixes #433

Merged
merged 1 commit into from
Dec 2, 2023
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
2 changes: 1 addition & 1 deletion examples/corpus-bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn run_encode(
_ => png::AdaptiveFilterType::NonAdaptive,
});
let mut encoder = encoder.write_header().unwrap();
encoder.write_image_data(&image).unwrap();
encoder.write_image_data(image).unwrap();
encoder.finish().unwrap();
reencoded
}
Expand Down
4 changes: 2 additions & 2 deletions examples/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ where
let src_rect = Rect {
left: 0,
bottom: 0,
width: src_dim.0 as u32,
height: src_dim.1 as u32,
width: src_dim.0,
height: src_dim.1,
};
let target_dim = target.get_dimensions();
let target_rect = BlitTarget {
Expand Down
6 changes: 3 additions & 3 deletions src/decoder/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ impl StreamingDecoder {
Ok((len - buf.len(), Decoded::Nothing))
}

fn next_state<'a>(
&'a mut self,
fn next_state(
&mut self,
buf: &[u8],
image_data: &mut Vec<u8>,
) -> Result<(usize, Decoded), DecodingError> {
Expand Down Expand Up @@ -1691,7 +1691,7 @@ mod tests {
let mut data = Vec::new();
data.write_u32::<byteorder::BigEndian>(sequence_number)
.unwrap();
data.write_all(&image_data).unwrap();
data.write_all(image_data).unwrap();
write_chunk(w, b"fdAT", &data);
}

Expand Down
38 changes: 19 additions & 19 deletions src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1673,6 +1673,25 @@ impl<W: Write> Drop for StreamWriter<'_, W> {
}
}

/// Mod to encapsulate the converters depending on the `deflate` crate.
///
/// Since this only contains trait impls, there is no need to make this public, they are simply
/// available when the mod is compiled as well.
impl Compression {
fn to_options(self) -> flate2::Compression {
#[allow(deprecated)]
match self {
Compression::Default => flate2::Compression::default(),
Compression::Fast => flate2::Compression::fast(),
Compression::Best => flate2::Compression::best(),
#[allow(deprecated)]
Compression::Huffman => flate2::Compression::none(),
#[allow(deprecated)]
Compression::Rle => flate2::Compression::none(),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -2374,22 +2393,3 @@ mod tests {
}
}
}

/// Mod to encapsulate the converters depending on the `deflate` crate.
///
/// Since this only contains trait impls, there is no need to make this public, they are simply
/// available when the mod is compiled as well.
impl Compression {
fn to_options(self) -> flate2::Compression {
#[allow(deprecated)]
match self {
Compression::Default => flate2::Compression::default(),
Compression::Fast => flate2::Compression::fast(),
Compression::Best => flate2::Compression::best(),
#[allow(deprecated)]
Compression::Huffman => flate2::Compression::none(),
#[allow(deprecated)]
Compression::Rle => flate2::Compression::none(),
}
}
}
12 changes: 5 additions & 7 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,11 @@ pub fn generate_rgba8_with_width(width: u32) -> Vec<u8> {
let mut row = Vec::new();
row.write_u8(0).unwrap(); // filter = no filter

let row_pixels = (0..width)
.map(|i| {
let color: u8 = (i * 255 / width) as u8;
let alpha: u8 = 0xff;
[color, 255 - color, color / 2, alpha]
})
.flatten();
let row_pixels = (0..width).flat_map(|i| {
let color: u8 = (i * 255 / width) as u8;
let alpha: u8 = 0xff;
[color, 255 - color, color / 2, alpha]
});
row.extend(row_pixels);

std::iter::repeat(row)
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ fn test_expand_adam7_bits() {
expected(start, 8, 4)
);

let start = (8 * line_no + 4) as usize * width as usize;
let start = (8 * line_no + 4) * width;

assert_eq!(
expand_adam7_bits(3, width, line_no, bits_pp).collect::<Vec<_>>(),
Expand Down