From a07368293e2310f22fb36173a5e11d8d91f22122 Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Mon, 5 Dec 2022 20:13:44 +0000 Subject: [PATCH 1/2] Fix clippy lint about format args --- serde_with/src/de/impls.rs | 6 +++--- serde_with/src/utils/duration.rs | 3 +-- serde_with/tests/serde_as/enum_map.rs | 2 +- serde_with/tests/version_numbers.rs | 3 +-- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/serde_with/src/de/impls.rs b/serde_with/src/de/impls.rs index ab8c608c..0f2e8e7e 100644 --- a/serde_with/src/de/impls.rs +++ b/serde_with/src/de/impls.rs @@ -222,7 +222,7 @@ where type Value = [T; M]; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.write_fmt(format_args!("an array of size {}", M)) + formatter.write_fmt(format_args!("an array of size {M}")) } fn visit_seq(self, seq: A) -> Result @@ -1327,7 +1327,7 @@ impl<'de, const N: usize> DeserializeAs<'de, [u8; N]> for Bytes { type Value = [u8; M]; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.write_fmt(format_args!("an byte array of size {}", M)) + formatter.write_fmt(format_args!("an byte array of size {M}")) } fn visit_seq(self, seq: A) -> Result @@ -1370,7 +1370,7 @@ impl<'de, const N: usize> DeserializeAs<'de, &'de [u8; N]> for Bytes { type Value = &'de [u8; M]; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.write_fmt(format_args!("a borrowed byte array of size {}", M)) + formatter.write_fmt(format_args!("a borrowed byte array of size {M}")) } fn visit_borrowed_bytes(self, v: &'de [u8]) -> Result diff --git a/serde_with/src/utils/duration.rs b/serde_with/src/utils/duration.rs index 968713da..832ea859 100644 --- a/serde_with/src/utils/duration.rs +++ b/serde_with/src/utils/duration.rs @@ -509,8 +509,7 @@ fn parse_float_into_time_parts(mut value: &str) -> Result<(Sign, u64, u32), Pars if subseclen > 9 { #[cfg(feature = "alloc")] return Err(ParseFloatError::Custom(alloc::format!( - "Duration and Timestamps with no more than 9 digits precision, but '{}' has more", - value + "Duration and Timestamps with no more than 9 digits precision, but '{value}' has more" ))); #[cfg(not(feature = "alloc"))] return Err(ParseFloatError::Custom( diff --git a/serde_with/tests/serde_as/enum_map.rs b/serde_with/tests/serde_as/enum_map.rs index aa55ea46..4d620c9d 100644 --- a/serde_with/tests/serde_as/enum_map.rs +++ b/serde_with/tests/serde_as/enum_map.rs @@ -9,7 +9,7 @@ fn bytes_debug_readable(bytes: &[u8]) -> String { for &byte in bytes { match byte { non_printable if !(0x20..0x7f).contains(&non_printable) => { - write!(result, "\\x{:02x}", byte).unwrap(); + write!(result, "\\x{byte:02x}").unwrap(); } b'\\' => result.push_str("\\\\"), _ => { diff --git a/serde_with/tests/version_numbers.rs b/serde_with/tests/version_numbers.rs index dbe76624..1cbf69fb 100644 --- a/serde_with/tests/version_numbers.rs +++ b/serde_with/tests/version_numbers.rs @@ -28,8 +28,7 @@ fn test_docs_rs_url_point_to_current_version() -> Result<(), Box Date: Mon, 5 Dec 2022 22:07:31 +0000 Subject: [PATCH 2/2] More formatting clippy fixes in optional code --- serde_with/src/base64.rs | 3 +-- serde_with/src/chrono_0_4.rs | 21 +++++++-------------- serde_with/src/hex.rs | 3 +-- serde_with/src/time_0_3.rs | 3 +-- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/serde_with/src/base64.rs b/serde_with/src/base64.rs index f3ec4781..1b221d3a 100644 --- a/serde_with/src/base64.rs +++ b/serde_with/src/base64.rs @@ -130,8 +130,7 @@ where let length = bytes.len(); bytes.try_into().map_err(|_e: T::Error| { DeError::custom(format_args!( - "Can't convert a Byte Vector of length {} to the output type.", - length + "Can't convert a Byte Vector of length {length} to the output type." )) }) } diff --git a/serde_with/src/chrono_0_4.rs b/serde_with/src/chrono_0_4.rs index a1f49745..a5cf829e 100644 --- a/serde_with/src/chrono_0_4.rs +++ b/serde_with/src/chrono_0_4.rs @@ -79,8 +79,7 @@ pub mod datetime_utc_ts_seconds_from_any { Ok(DateTime::::from_utc(ndt, Utc)) } else { Err(DeError::custom(format_args!( - "a timestamp which can be represented in a DateTime but received '{}'", - value + "a timestamp which can be represented in a DateTime but received '{value}'" ))) } } @@ -94,8 +93,7 @@ pub mod datetime_utc_ts_seconds_from_any { Ok(DateTime::::from_utc(ndt, Utc)) } else { Err(DeError::custom(format_args!( - "a timestamp which can be represented in a DateTime but received '{}'", - value + "a timestamp which can be represented in a DateTime but received '{value}'" ))) } } @@ -111,8 +109,7 @@ pub mod datetime_utc_ts_seconds_from_any { Ok(DateTime::::from_utc(ndt, Utc)) } else { Err(DeError::custom(format_args!( - "a timestamp which can be represented in a DateTime but received '{}'", - value + "a timestamp which can be represented in a DateTime but received '{value}'" ))) } } @@ -131,8 +128,7 @@ pub mod datetime_utc_ts_seconds_from_any { Ok(DateTime::::from_utc(ndt, Utc)) } else { Err(DeError::custom(format_args!( - "a timestamp which can be represented in a DateTime but received '{}'", - value + "a timestamp which can be represented in a DateTime but received '{value}'" ))) } } else { @@ -144,8 +140,7 @@ pub mod datetime_utc_ts_seconds_from_any { let subseclen = subseconds.chars().count() as u32; if subseclen > 9 { return Err(DeError::custom(format_args!( - "DateTimes only support nanosecond precision but '{}' has more than 9 digits.", - value + "DateTimes only support nanosecond precision but '{value}' has more than 9 digits." ))); } @@ -157,8 +152,7 @@ pub mod datetime_utc_ts_seconds_from_any { Ok(DateTime::::from_utc(ndt, Utc)) } else { Err(DeError::custom(format_args!( - "a timestamp which can be represented in a DateTime but received '{}'", - value + "a timestamp which can be represented in a DateTime but received '{value}'" ))) } } else { @@ -220,8 +214,7 @@ where Ok(dur) => dur, Err(msg) => { return Err(DeError::custom(format_args!( - "Duration is outside of the representable range: {}", - msg + "Duration is outside of the representable range: {msg}" ))) } }; diff --git a/serde_with/src/hex.rs b/serde_with/src/hex.rs index e52c6f3d..b1043214 100644 --- a/serde_with/src/hex.rs +++ b/serde_with/src/hex.rs @@ -135,8 +135,7 @@ where let length = vec.len(); vec.try_into().map_err(|_e: T::Error| { DeError::custom(format_args!( - "Can't convert a Byte Vector of length {} to the output type.", - length + "Can't convert a Byte Vector of length {length} to the output type." )) }) }) diff --git a/serde_with/src/time_0_3.rs b/serde_with/src/time_0_3.rs index 748c6877..823959fd 100644 --- a/serde_with/src/time_0_3.rs +++ b/serde_with/src/time_0_3.rs @@ -49,8 +49,7 @@ where Ok(dur) => dur, Err(msg) => { return Err(DeError::custom(format_args!( - "Duration is outside of the representable range: {}", - msg + "Duration is outside of the representable range: {msg}" ))) } };