From f24a9fa8b1fc3c0bcb1d0ed49420896ee847af23 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Wed, 15 Sep 2021 19:09:17 +0200 Subject: [PATCH] Fix clippy warnings --- examples/nunchuck.rs | 5 ++--- examples/sensors.rs | 4 ++-- src/ffi.rs | 10 +++++----- src/mock.rs | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/examples/nunchuck.rs b/examples/nunchuck.rs index de1c96de..fc2b67df 100644 --- a/examples/nunchuck.rs +++ b/examples/nunchuck.rs @@ -122,10 +122,9 @@ mod nunchuck { let mut buf: [u8; 6] = [0; 6]; // tell the nunchuck to prepare a sample - try!(self - .i2cdev + self.i2cdev .smbus_write_byte(0x00) - .map_err(NunchuckError::Error)); + .map_err(NunchuckError::Error)?; // now, read it! thread::sleep(Duration::from_millis(10)); diff --git a/examples/sensors.rs b/examples/sensors.rs index 189c6b7e..a9f3f7ba 100644 --- a/examples/sensors.rs +++ b/examples/sensors.rs @@ -173,8 +173,8 @@ mod sensors { i2cdev.smbus_write_byte_data(REGISTER_POWER_CTL, 0x00)?; // configure some defaults - try!(i2cdev - .smbus_write_byte_data(REGISTER_BW_RATE, ADXL345DataRate::RATE_1600HZ as u8)); + i2cdev + .smbus_write_byte_data(REGISTER_BW_RATE, ADXL345DataRate::RATE_1600HZ as u8)?; i2cdev.smbus_write_byte_data(REGISTER_DATA_FORMAT, 0x08)?; i2cdev.smbus_write_byte_data(REGISTER_OFSX, 0xFD)?; i2cdev.smbus_write_byte_data(REGISTER_OFSY, 0x03)?; diff --git a/src/ffi.rs b/src/ffi.rs index 1236c579..472ecb13 100644 --- a/src/ffi.rs +++ b/src/ffi.rs @@ -174,7 +174,7 @@ unsafe fn i2c_smbus_access( size: I2CSMBusSize, data: *mut i2c_smbus_data, ) -> Result<(), I2CError> { - let mut args = i2c_smbus_ioctl_data { + let args = i2c_smbus_ioctl_data { read_write: read_write as u8, command, size: size as u32, @@ -182,7 +182,7 @@ unsafe fn i2c_smbus_access( }; // remove type information - ioctl::i2c_smbus(fd, &mut args).map(drop) + ioctl::i2c_smbus(fd, &args).map(drop) } #[inline] @@ -375,7 +375,7 @@ fn copy_to_i2c_block_data(values: &[u8], max_size: usize) -> i2c_smbus_data { #[inline] pub fn i2c_smbus_write_block_data(fd: RawFd, register: u8, values: &[u8]) -> Result<(), I2CError> { - let mut data = copy_to_i2c_block_data(&values, 32); + let mut data = copy_to_i2c_block_data(values, 32); unsafe { i2c_smbus_access( fd, @@ -393,7 +393,7 @@ pub fn i2c_smbus_write_i2c_block_data( register: u8, values: &[u8], ) -> Result<(), I2CError> { - let mut data = copy_to_i2c_block_data(&values, 32); + let mut data = copy_to_i2c_block_data(values, 32); unsafe { i2c_smbus_access( fd, @@ -411,7 +411,7 @@ pub fn i2c_smbus_process_call_block( register: u8, values: &[u8], ) -> Result, I2CError> { - let mut data = copy_to_i2c_block_data(&values, 31); + let mut data = copy_to_i2c_block_data(values, 31); unsafe { i2c_smbus_access( fd, diff --git a/src/mock.rs b/src/mock.rs index bc292e88..058708a9 100644 --- a/src/mock.rs +++ b/src/mock.rs @@ -35,7 +35,7 @@ impl I2CRegisterMap { /// Set several registers starting at the given offset pub fn write_regs(&mut self, offset: usize, data: &[u8]) { println!("WRITE | 0x{:X} : {:?}", offset, data); - self.registers[offset..(data.len() + offset)].clone_from_slice(&data); + self.registers[offset..(data.len() + offset)].clone_from_slice(data); } }