From c679803e95a0c7051e996837df1ffcea716cc800 Mon Sep 17 00:00:00 2001 From: Rafael Bachmann Date: Thu, 23 Sep 2021 20:06:01 +0200 Subject: [PATCH] Fix clippy lints --- src/cb.rs | 2 +- src/command/gatt.rs | 4 ++-- src/event/command.rs | 12 ++++++------ src/event/mod.rs | 19 +++++++++---------- src/lib.rs | 4 ++-- tests/command_complete.rs | 2 +- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/cb.rs b/src/cb.rs index 054e408..d280b75 100644 --- a/src/cb.rs +++ b/src/cb.rs @@ -65,7 +65,7 @@ where self.buffer[(self.read_index + n) % self.buffer.len()] } - pub fn take_slice<'b>(&mut self, n: usize, buf: &'b mut [T]) { + pub fn take_slice(&mut self, n: usize, buf: &mut [T]) { if n > self.size() { panic!( "Not enough data to read (wanted {}, have {})", diff --git a/src/command/gatt.rs b/src/command/gatt.rs index 99ea37f..8396f84 100644 --- a/src/command/gatt.rs +++ b/src/command/gatt.rs @@ -1922,7 +1922,7 @@ impl<'a> FindByTypeValueParameters<'a> { LittleEndian::write_u16(&mut bytes[4..6], self.attribute_handle_range.to.0); LittleEndian::write_u16(&mut bytes[6..8], self.uuid.0); bytes[8] = self.value.len() as u8; - bytes[9..9 + self.value.len()].copy_from_slice(&self.value); + bytes[9..9 + self.value.len()].copy_from_slice(self.value); 9 + self.value.len() } @@ -1989,7 +1989,7 @@ impl<'a> WriteRequest<'a> { LittleEndian::write_u16(&mut bytes[2..4], self.attribute_handle.0); LittleEndian::write_u16(&mut bytes[4..6], self.offset as u16); bytes[6] = self.value.len() as u8; - bytes[7..7 + self.value.len()].copy_from_slice(&self.value); + bytes[7..7 + self.value.len()].copy_from_slice(self.value); 7 + self.value.len() } diff --git a/src/event/command.rs b/src/event/command.rs index 1788583..8348b15 100644 --- a/src/event/command.rs +++ b/src/event/command.rs @@ -578,7 +578,7 @@ fn to_hal_config_parameter( Ok(HalConfigParameter::PublicAddress(hci::BdAddr(buf))) } 2 => Ok(HalConfigParameter::Diversifier(LittleEndian::read_u16( - &bytes, + bytes, ))), 16 => { let mut buf = [0; 16]; @@ -842,7 +842,7 @@ pub struct GapResolvePrivateAddress { fn to_gap_resolve_private_address( bytes: &[u8], ) -> Result> { - let status = to_status(&bytes)?; + let status = to_status(bytes)?; if status == hci::Status::Success { require_len!(bytes, 7); @@ -896,7 +896,7 @@ impl Debug for GapBondedDevices { fn to_gap_bonded_devices( bytes: &[u8], ) -> Result> { - let status = to_status(&bytes)?; + let status = to_status(bytes)?; match status { hci::Status::Success => { const HEADER_LEN: usize = 2; @@ -954,7 +954,7 @@ fn to_gatt_service(bytes: &[u8]) -> Result for Status { } } -impl Into for Status { - fn into(self) -> u8 { - self as u8 +impl From for u8 { + fn from(status: Status) -> Self { + status as u8 } } @@ -561,7 +561,7 @@ macro_rules! require_len_at_least { fn first_16(buffer: &[T]) -> &[T] { if buffer.len() < 16 { - &buffer + buffer } else { &buffer[..16] } @@ -799,7 +799,7 @@ impl TryFrom for ResetReason { fn to_hal_initialized(buffer: &[u8]) -> Result> { require_len!(buffer, 3); - Ok(buffer[2].try_into().map_err(hci::event::Error::Vendor)?) + buffer[2].try_into().map_err(hci::event::Error::Vendor) } #[cfg(feature = "ms")] @@ -935,8 +935,7 @@ fn to_lost_event(buffer: &[u8]) -> Result HandleInfoPairIterator { HandleInfoPairIterator { - event: &self, + event: self, next_index: 0, } } @@ -1990,7 +1989,7 @@ impl AttReadByTypeResponse { /// Return an iterator over all valid handle-value pairs returned with the response. pub fn handle_value_pair_iter(&self) -> HandleValuePairIterator { HandleValuePairIterator { - event: &self, + event: self, index: 0, } } @@ -2050,7 +2049,7 @@ fn to_att_read_by_type_response( let mut full_handle_value_pair_buf = [0; MAX_HANDLE_VALUE_PAIR_BUF_LEN]; full_handle_value_pair_buf[..handle_value_pair_buf.len()] - .copy_from_slice(&handle_value_pair_buf); + .copy_from_slice(handle_value_pair_buf); Ok(AttReadByTypeResponse { conn_handle: ConnectionHandle(LittleEndian::read_u16(&buffer[2..])), diff --git a/src/lib.rs b/src/lib.rs index 0d6b76b..7509479 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -304,7 +304,7 @@ where let mut header = [0; HEADER_LEN]; hci::host::uart::CommandHeader::new(opcode, params.len()).copy_into_slice(&mut header); - self.write(&header, ¶ms) + self.write(&header, params) } } @@ -464,7 +464,7 @@ where /// provided SPI bus handle. /// /// Returns the result of the invoked body. - pub fn with_spi<'spi, T, F, E>(&mut self, spi: &'spi mut SPI, body: F) -> T + pub fn with_spi(&mut self, spi: &mut SPI, body: F) -> T where F: FnOnce(&mut ActiveBlueNRG) -> T, SPI: emhal::blocking::spi::transfer::Default diff --git a/tests/command_complete.rs b/tests/command_complete.rs index c77d10c..27ddc5e 100644 --- a/tests/command_complete.rs +++ b/tests/command_complete.rs @@ -132,7 +132,7 @@ fn hal_write_config_data_nonstandard_status() { (0xF0, Status::ProfileAlreadyInitialized), (0xF1, Status::NullParameter), ] - .iter() + .iter() { let buffer = [0x0E, 4, 8, 0x0C, 0xFC, *code]; match Event::new(Packet(&buffer)) {