Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
barafael authored and Rafael Bachmann committed Sep 23, 2021
1 parent 9f5010e commit c679803
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/cb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {})",
Expand Down
4 changes: 2 additions & 2 deletions src/command/gatt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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()
}
Expand Down
12 changes: 6 additions & 6 deletions src/event/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -842,7 +842,7 @@ pub struct GapResolvePrivateAddress {
fn to_gap_resolve_private_address(
bytes: &[u8],
) -> Result<GapResolvePrivateAddress, hci::event::Error<super::BlueNRGError>> {
let status = to_status(&bytes)?;
let status = to_status(bytes)?;
if status == hci::Status::Success {
require_len!(bytes, 7);

Expand Down Expand Up @@ -896,7 +896,7 @@ impl Debug for GapBondedDevices {
fn to_gap_bonded_devices(
bytes: &[u8],
) -> Result<GapBondedDevices, hci::event::Error<super::BlueNRGError>> {
let status = to_status(&bytes)?;
let status = to_status(bytes)?;
match status {
hci::Status::Success => {
const HEADER_LEN: usize = 2;
Expand Down Expand Up @@ -954,7 +954,7 @@ fn to_gatt_service(bytes: &[u8]) -> Result<GattService, hci::event::Error<super:
require_len!(bytes, 3);

Ok(GattService {
status: to_status(&bytes)?,
status: to_status(bytes)?,
service_handle: crate::gatt::ServiceHandle(LittleEndian::read_u16(&bytes[1..3])),
})
}
Expand All @@ -976,7 +976,7 @@ fn to_gatt_characteristic(
require_len!(bytes, 3);

Ok(GattCharacteristic {
status: to_status(&bytes)?,
status: to_status(bytes)?,
characteristic_handle: crate::gatt::CharacteristicHandle(LittleEndian::read_u16(
&bytes[1..3],
)),
Expand All @@ -1000,7 +1000,7 @@ fn to_gatt_characteristic_descriptor(
require_len!(bytes, 3);

Ok(GattCharacteristicDescriptor {
status: to_status(&bytes)?,
status: to_status(bytes)?,
descriptor_handle: crate::gatt::DescriptorHandle(LittleEndian::read_u16(&bytes[1..3])),
})
}
Expand Down
19 changes: 9 additions & 10 deletions src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@ impl TryFrom<u8> for Status {
}
}

impl Into<u8> for Status {
fn into(self) -> u8 {
self as u8
impl From<Status> for u8 {
fn from(status: Status) -> Self {
status as u8
}
}

Expand Down Expand Up @@ -561,7 +561,7 @@ macro_rules! require_len_at_least {

fn first_16<T>(buffer: &[T]) -> &[T] {
if buffer.len() < 16 {
&buffer
buffer
} else {
&buffer[..16]
}
Expand Down Expand Up @@ -799,7 +799,7 @@ impl TryFrom<u8> for ResetReason {
fn to_hal_initialized(buffer: &[u8]) -> Result<ResetReason, hci::event::Error<BlueNRGError>> {
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")]
Expand Down Expand Up @@ -935,8 +935,7 @@ fn to_lost_event(buffer: &[u8]) -> Result<EventFlags, hci::event::Error<BlueNRGE
require_len!(buffer, 10);

let bits = LittleEndian::read_u64(&buffer[2..]);
EventFlags::from_bits(bits)
.ok_or_else(|| hci::event::Error::Vendor(BlueNRGError::BadEventFlags(bits)))
EventFlags::from_bits(bits).ok_or(hci::event::Error::Vendor(BlueNRGError::BadEventFlags(bits)))
}

// The maximum length of [`FaultData::debug_data`]. The maximum length of an event is 255 bytes,
Expand Down Expand Up @@ -1860,7 +1859,7 @@ impl AttFindByTypeValueResponse {
/// spec.
pub fn handle_pairs_iter(&self) -> HandleInfoPairIterator {
HandleInfoPairIterator {
event: &self,
event: self,
next_index: 0,
}
}
Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -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..])),
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, &params)
self.write(&header, params)
}
}

Expand Down Expand Up @@ -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<T, F, E>(&mut self, spi: &mut SPI, body: F) -> T
where
F: FnOnce(&mut ActiveBlueNRG<SPI, OutputPin1, OutputPin2, InputPin, GpioError>) -> T,
SPI: emhal::blocking::spi::transfer::Default<u8, Error = E>
Expand Down
2 changes: 1 addition & 1 deletion tests/command_complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit c679803

Please sign in to comment.