From 63dfdaf0d9ae45db9ce244dd5a66be1612429360 Mon Sep 17 00:00:00 2001 From: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:16:44 +0100 Subject: [PATCH] make clippy happy Signed-off-by: Andrei Gherghescu <8067229+andrei-ng@users.noreply.github.com> --- ublox/src/parser.rs | 14 +++++------ ublox/src/ubx_packets/packets.rs | 40 ++++++++++++++++---------------- ublox_derive/src/output.rs | 2 +- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/ublox/src/parser.rs b/ublox/src/parser.rs index fae2020..c680715 100644 --- a/ublox/src/parser.rs +++ b/ublox/src/parser.rs @@ -62,7 +62,7 @@ impl UnderlyingBuffer for Vec { } fn max_capacity(&self) -> usize { - core::usize::MAX + usize::MAX } fn extend_from_slice(&mut self, other: &[u8]) -> usize { @@ -93,7 +93,7 @@ impl<'a> FixedLinearBuffer<'a> { } } -impl<'a> core::ops::Index> for FixedLinearBuffer<'a> { +impl core::ops::Index> for FixedLinearBuffer<'_> { type Output = [u8]; fn index(&self, index: core::ops::Range) -> &Self::Output { @@ -104,7 +104,7 @@ impl<'a> core::ops::Index> for FixedLinearBuffer<'a> { } } -impl<'a> core::ops::Index for FixedLinearBuffer<'a> { +impl core::ops::Index for FixedLinearBuffer<'_> { type Output = u8; fn index(&self, index: usize) -> &Self::Output { @@ -112,7 +112,7 @@ impl<'a> core::ops::Index for FixedLinearBuffer<'a> { } } -impl<'a> UnderlyingBuffer for FixedLinearBuffer<'a> { +impl UnderlyingBuffer for FixedLinearBuffer<'_> { fn clear(&mut self) { self.len = 0; } @@ -213,7 +213,7 @@ struct DualBuffer<'a, T: UnderlyingBuffer> { new_buf_offset: usize, } -impl<'a, T: UnderlyingBuffer> core::ops::Index for DualBuffer<'a, T> { +impl core::ops::Index for DualBuffer<'_, T> { type Output = u8; fn index(&self, index: usize) -> &u8 { @@ -375,7 +375,7 @@ impl<'a, T: UnderlyingBuffer> DualBuffer<'a, T> { } } -impl<'a, T: UnderlyingBuffer> Drop for DualBuffer<'a, T> { +impl Drop for DualBuffer<'_, T> { fn drop(&mut self) { self.buf.drain(self.off); self.buf @@ -416,7 +416,7 @@ pub struct ParserIter<'a, T: UnderlyingBuffer> { buf: DualBuffer<'a, T>, } -impl<'a, T: UnderlyingBuffer> ParserIter<'a, T> { +impl ParserIter<'_, T> { fn find_sync(&self) -> Option { (0..self.buf.len()).find(|&i| self.buf[i] == SYNC_CHAR_1) } diff --git a/ublox/src/ubx_packets/packets.rs b/ublox/src/ubx_packets/packets.rs index db89e3a..5ebafa5 100644 --- a/ublox/src/ubx_packets/packets.rs +++ b/ublox/src/ubx_packets/packets.rs @@ -1295,7 +1295,7 @@ struct AckAck { msg_id: u8, } -impl<'a> AckAckRef<'a> { +impl AckAckRef<'_> { pub fn is_ack_for(&self) -> bool { self.class() == T::CLASS && self.msg_id() == T::ID } @@ -1312,7 +1312,7 @@ struct AckNak { msg_id: u8, } -impl<'a> AckNakRef<'a> { +impl AckNakRef<'_> { pub fn is_nak_for(&self) -> bool { self.class() == T::CLASS && self.msg_id() == T::ID } @@ -1799,7 +1799,7 @@ impl<'a> CfgValIter<'a> { } } -impl<'a> core::iter::Iterator for CfgValIter<'a> { +impl core::iter::Iterator for CfgValIter<'_> { type Item = CfgVal; fn next(&mut self) -> Option { @@ -2395,10 +2395,10 @@ struct ScaleBack(T); impl ScaleBack { fn as_i8(self, x: T) -> i8 { let x = (x * self.0).round(); - if x < T::from_i8(i8::min_value()).unwrap() { - i8::min_value() - } else if x > T::from_i8(i8::max_value()).unwrap() { - i8::max_value() + if x < T::from_i8(i8::MIN).unwrap() { + i8::MIN + } else if x > T::from_i8(i8::MAX).unwrap() { + i8::MAX } else { x.to_i8().unwrap() } @@ -2406,10 +2406,10 @@ impl ScaleBack { fn as_i16(self, x: T) -> i16 { let x = (x * self.0).round(); - if x < T::from_i16(i16::min_value()).unwrap() { - i16::min_value() - } else if x > T::from_i16(i16::max_value()).unwrap() { - i16::max_value() + if x < T::from_i16(i16::MIN).unwrap() { + i16::MIN + } else if x > T::from_i16(i16::MAX).unwrap() { + i16::MAX } else { x.to_i16().unwrap() } @@ -3155,7 +3155,7 @@ impl EsfMeas { } } -impl<'a> EsfMeasRef<'a> { +impl EsfMeasRef<'_> { fn data_len(&self) -> usize { self.flags().num_meas() as usize * 4 } @@ -3239,7 +3239,7 @@ impl<'a> EsfMeasDataIter<'a> { } } -impl<'a> core::iter::Iterator for EsfMeasDataIter<'a> { +impl core::iter::Iterator for EsfMeasDataIter<'_> { type Item = EsfMeasData; fn next(&mut self) -> Option { @@ -3252,7 +3252,7 @@ impl<'a> core::iter::Iterator for EsfMeasDataIter<'a> { } Some(EsfMeasData { - data_type: (((data & 0x3F000000) >> 24) as u8).try_into().unwrap(), + data_type: (((data & 0x3F000000) >> 24) as u8).into(), data_field, }) } @@ -3343,7 +3343,7 @@ impl<'a> EsfRawDataIter<'a> { } } -impl<'a> core::iter::Iterator for EsfRawDataIter<'a> { +impl core::iter::Iterator for EsfRawDataIter<'_> { type Item = EsfRawData; fn next(&mut self) -> Option { @@ -3659,17 +3659,17 @@ impl<'a> EsfStatusDataIter<'a> { } } -impl<'a> core::iter::Iterator for EsfStatusDataIter<'a> { +impl core::iter::Iterator for EsfStatusDataIter<'_> { type Item = EsfStatusData; fn next(&mut self) -> Option { let chunk = self.0.next()?; let data = u32::from_le_bytes(chunk[0..4].try_into().unwrap()); Some(EsfStatusData { - sens_status1: ((data & 0xFF) as u8).try_into().unwrap(), - sens_status2: (((data >> 8) & 0xFF) as u8).try_into().unwrap(), + sens_status1: ((data & 0xFF) as u8).into(), + sens_status2: (((data >> 8) & 0xFF) as u8).into(), freq: ((data >> 16) & 0xFF).try_into().unwrap(), - faults: (((data >> 24) & 0xFF) as u8).try_into().unwrap(), + faults: (((data >> 24) & 0xFF) as u8).into(), }) } } @@ -4024,7 +4024,7 @@ impl<'a> DwrdIter<'a> { } } -impl<'a> core::iter::Iterator for DwrdIter<'a> { +impl core::iter::Iterator for DwrdIter<'_> { type Item = u32; fn next(&mut self) -> Option { diff --git a/ublox_derive/src/output.rs b/ublox_derive/src/output.rs index 7e1ba73..d6ba7c0 100644 --- a/ublox_derive/src/output.rs +++ b/ublox_derive/src/output.rs @@ -505,7 +505,7 @@ pub fn generate_code_to_extend_enum(ubx_enum: &UbxExtendEnum) -> TokenStream { let attrs = &ubx_enum.attrs; if let Some(UbxEnumRestHandling::Reserved) = ubx_enum.rest_handling { let defined: HashSet = ubx_enum.variants.iter().map(|x| x.1).collect(); - for i in 0..=u8::max_value() { + for i in 0..=u8::MAX { if !defined.contains(&i) { let name = format_ident!("Reserved{}", i); variants.push((name, i));