From f6a762b72c8650067b815d11a43492756444807e Mon Sep 17 00:00:00 2001 From: "A. Molzer" <5550310+197g@users.noreply.github.com> Date: Mon, 14 Jul 2025 18:09:55 +0200 Subject: [PATCH] Upgrade usage of format! and Default --- src/encoder/compression/deflate.rs | 8 ++------ src/encoder/tiff_value.rs | 2 +- tests/decode_images.rs | 6 +++--- tests/encode_images.rs | 2 +- tests/encode_images_with_compression.rs | 4 ++-- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/encoder/compression/deflate.rs b/src/encoder/compression/deflate.rs index a8a052e..3e5d528 100644 --- a/src/encoder/compression/deflate.rs +++ b/src/encoder/compression/deflate.rs @@ -11,21 +11,17 @@ pub struct Deflate { /// It allows trading compression ratio for compression speed. #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] #[non_exhaustive] +#[derive(Default)] pub enum DeflateLevel { /// The fastest possible compression mode. Fast = 1, /// The conserative choice between speed and ratio. + #[default] Balanced = 6, /// The best compression available with Deflate. Best = 9, } -impl Default for DeflateLevel { - fn default() -> Self { - DeflateLevel::Balanced - } -} - impl Deflate { /// Create a new deflate compressor with a specific level of compression. pub fn with_level(level: DeflateLevel) -> Self { diff --git a/src/encoder/tiff_value.rs b/src/encoder/tiff_value.rs index 43653f4..c9b7af9 100644 --- a/src/encoder/tiff_value.rs +++ b/src/encoder/tiff_value.rs @@ -450,7 +450,7 @@ impl TiffValue for str { } } -impl<'a, T: TiffValue + ?Sized> TiffValue for &'a T { +impl TiffValue for &'_ T { const BYTE_LEN: u8 = T::BYTE_LEN; const FIELD_TYPE: Type = T::FIELD_TYPE; diff --git a/tests/decode_images.rs b/tests/decode_images.rs index 5a62279..a459c86 100644 --- a/tests/decode_images.rs +++ b/tests/decode_images.rs @@ -348,7 +348,7 @@ fn test_div_zero() { match err { TiffError::FormatError(TiffFormatError::StripTileTagConflict) => {} - unexpected => panic!("Unexpected error {}", unexpected), + unexpected => panic!("Unexpected error {unexpected}"), } } @@ -366,7 +366,7 @@ fn test_too_many_value_bytes() { match error { tiff::TiffError::LimitsExceeded => {} - unexpected => panic!("Unexpected error {}", unexpected), + unexpected => panic!("Unexpected error {unexpected}"), } } @@ -497,7 +497,7 @@ fn timeout() { match error { TiffError::FormatError(TiffFormatError::CycleInOffsets) => {} - e => panic!("Unexpected error {:?}", e), + e => panic!("Unexpected error {e:?}"), } } diff --git a/tests/encode_images.rs b/tests/encode_images.rs index af9f610..c183543 100644 --- a/tests/encode_images.rs +++ b/tests/encode_images.rs @@ -621,7 +621,7 @@ fn test_rows_per_strip() { let img2 = [i; 2 * 100]; match decoder.read_chunk(i as u32).unwrap() { DecodingResult::U8(data) => assert_eq!(&img2[..], &data[..]), - other => panic!("Incorrect strip type {:?}", other), + other => panic!("Incorrect strip type {other:?}"), } } } diff --git a/tests/encode_images_with_compression.rs b/tests/encode_images_with_compression.rs index 9b8a92f..a355fb1 100644 --- a/tests/encode_images_with_compression.rs +++ b/tests/encode_images_with_compression.rs @@ -116,7 +116,7 @@ fn encode_decode_with_compression(compression: Compression) { assert_eq!( match decoder.read_image() { Ok(DecodingResult::U16(image_data)) => image_data, - unexpected => panic!("Descoding RGB failed: {:?}", unexpected), + unexpected => panic!("Descoding RGB failed: {unexpected:?}"), }, image_rgb.reference_data() ); @@ -126,7 +126,7 @@ fn encode_decode_with_compression(compression: Compression) { assert_eq!( match decoder.read_image() { Ok(DecodingResult::U8(image_data)) => image_data, - unexpected => panic!("Decoding grayscale failed: {:?}", unexpected), + unexpected => panic!("Decoding grayscale failed: {unexpected:?}"), }, image_grayscale.reference_data() );