From a9ca3aec2ff25a6f662e5929ae53ff31aab53e05 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 11 Feb 2024 12:04:00 -0800 Subject: [PATCH 1/4] Update MSRV and fix clippy issues --- Cargo.toml | 2 +- src/codecs/png.rs | 16 ++++------------ src/codecs/webp/encoder.rs | 1 + src/codecs/webp/vp8.rs | 23 ++++++----------------- 4 files changed, 12 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c7cfd08393..59bfee1d2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2021" resolver = "2" # note: when changed, also update test runner in `.github/workflows/rust.yml` -rust-version = "1.61.0" +rust-version = "1.63.0" license = "MIT OR Apache-2.0" description = "Imaging library. Provides basic image processing and encoders/decoders for common image formats." diff --git a/src/codecs/png.rs b/src/codecs/png.rs index 39e1e5cb97..d2d0bf6898 100644 --- a/src/codecs/png.rs +++ b/src/codecs/png.rs @@ -551,10 +551,12 @@ pub struct PngEncoder { /// Compression level of a PNG encoder. The default setting is `Fast`. #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[non_exhaustive] +#[derive(Default)] pub enum CompressionType { /// Default compression level Default, /// Fast, minimal compression + #[default] Fast, /// High compression level Best, @@ -571,6 +573,7 @@ pub enum CompressionType { /// The default filter is `Adaptive`. #[derive(Clone, Copy, Debug, Eq, PartialEq)] #[non_exhaustive] +#[derive(Default)] pub enum FilterType { /// No processing done, best used for low bit depth grayscale or data with a /// low color count @@ -585,6 +588,7 @@ pub enum FilterType { Paeth, /// Uses a heuristic to select one of the preceding filters for each /// scanline rather than one filter for the entire image + #[default] Adaptive, } @@ -769,18 +773,6 @@ impl ImageError { } } -impl Default for CompressionType { - fn default() -> Self { - CompressionType::Fast - } -} - -impl Default for FilterType { - fn default() -> Self { - FilterType::Adaptive - } -} - impl fmt::Display for BadPngRepresentation { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { diff --git a/src/codecs/webp/encoder.rs b/src/codecs/webp/encoder.rs index 8fb125b65b..4f809f901e 100644 --- a/src/codecs/webp/encoder.rs +++ b/src/codecs/webp/encoder.rs @@ -32,6 +32,7 @@ pub struct WebPQuality(Quality); #[derive(Debug, Copy, Clone)] enum Quality { Lossless, + #[allow(unused)] #[deprecated = "Lossy encoding will be removed in a future version. See: https://github.com/image-rs/image/issues/1984"] Lossy(u8), } diff --git a/src/codecs/webp/vp8.rs b/src/codecs/webp/vp8.rs index f18b64aeb4..3d4fe96012 100644 --- a/src/codecs/webp/vp8.rs +++ b/src/codecs/webp/vp8.rs @@ -51,8 +51,10 @@ const B_HU_PRED: i8 = 9; // Prediction mode enum #[repr(i8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Default)] enum LumaMode { /// Predict DC using row above and column to the left. + #[default] DC = DC_PRED, /// Predict rows using row above. @@ -70,8 +72,10 @@ enum LumaMode { #[repr(i8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Default)] enum ChromaMode { /// Predict DC using row above and column to the left. + #[default] DC = DC_PRED, /// Predict rows using row above. @@ -86,7 +90,9 @@ enum ChromaMode { #[repr(i8)] #[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Default)] enum IntraMode { + #[default] DC = B_DC_PRED, TM = B_TM_PRED, VE = B_VE_PRED, @@ -2126,12 +2132,6 @@ impl LumaMode { } } -impl Default for LumaMode { - fn default() -> Self { - LumaMode::DC - } -} - impl ChromaMode { fn from_i8(val: i8) -> Option { Some(match val { @@ -2144,12 +2144,6 @@ impl ChromaMode { } } -impl Default for ChromaMode { - fn default() -> Self { - ChromaMode::DC - } -} - impl IntraMode { fn from_i8(val: i8) -> Option { Some(match val { @@ -2168,11 +2162,6 @@ impl IntraMode { } } -impl Default for IntraMode { - fn default() -> Self { - IntraMode::DC - } -} fn init_top_macroblocks(width: usize) -> Vec { let mb_width = (width + 15) / 16; From 0d88580e081e7a639f5c2907d61dfd581ae1b597 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 11 Feb 2024 12:05:53 -0800 Subject: [PATCH 2/4] Cargo fmt --- src/codecs/webp/vp8.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/codecs/webp/vp8.rs b/src/codecs/webp/vp8.rs index 3d4fe96012..bebd1d1d49 100644 --- a/src/codecs/webp/vp8.rs +++ b/src/codecs/webp/vp8.rs @@ -50,8 +50,7 @@ const B_HU_PRED: i8 = 9; // Prediction mode enum #[repr(i8)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[derive(Default)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] enum LumaMode { /// Predict DC using row above and column to the left. #[default] @@ -71,8 +70,7 @@ enum LumaMode { } #[repr(i8)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[derive(Default)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] enum ChromaMode { /// Predict DC using row above and column to the left. #[default] @@ -89,8 +87,7 @@ enum ChromaMode { } #[repr(i8)] -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -#[derive(Default)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] enum IntraMode { #[default] DC = B_DC_PRED, @@ -2162,7 +2159,6 @@ impl IntraMode { } } - fn init_top_macroblocks(width: usize) -> Vec { let mb_width = (width + 15) / 16; From 9f090fdc44be1ac635145b11a042c610aaf81071 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 11 Feb 2024 12:09:00 -0800 Subject: [PATCH 3/4] Fix workflow as well --- .github/workflows/rust.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 679c40c68a..e9865f408e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -38,14 +38,14 @@ jobs: strategy: fail-fast: false matrix: - rust: ["1.61.0", nightly, beta] + rust: ["1.63.0", nightly, beta] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly - if: ${{ matrix.rust == '1.61.0' }} + if: ${{ matrix.rust == '1.63.0' }} - name: Generate Cargo.lock with minimal-version dependencies - if: ${{ matrix.rust == '1.61.0' }} + if: ${{ matrix.rust == '1.63.0' }} run: cargo -Zminimal-versions generate-lockfile - uses: dtolnay/rust-toolchain@v1 @@ -58,7 +58,7 @@ jobs: - name: build run: cargo build -v --features webp,webp-encoder - name: test - if: ${{ matrix.rust != '1.61.0' }} + if: ${{ matrix.rust != '1.63.0' }} run: > cargo test -v --features webp,webp-encoder && cargo doc -v --features webp,webp-encoder From fba4b6cedc801049cc4c1cb98d3ee38e1fb8281b Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sun, 11 Feb 2024 12:22:35 -0800 Subject: [PATCH 4/4] Another clippy fix --- src/codecs/pnm/decoder.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/codecs/pnm/decoder.rs b/src/codecs/pnm/decoder.rs index 03faf7c084..9105662269 100644 --- a/src/codecs/pnm/decoder.rs +++ b/src/codecs/pnm/decoder.rs @@ -421,13 +421,6 @@ trait HeaderReader: BufRead { Ok(string) } - /// Read the next line - fn read_next_line(&mut self) -> ImageResult { - let mut buffer = String::new(); - self.read_line(&mut buffer)?; - Ok(buffer) - } - fn read_next_u32(&mut self) -> ImageResult { let s = self.read_next_string()?; s.parse::()