From 34056fa893d45e63a9ab9e58910975a9c2c4c362 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sat, 10 Aug 2024 17:08:44 +0200 Subject: [PATCH] all: clippy fixes --- ethercat-sys/build.rs | 2 +- examples/cyclic-data.rs | 15 +++++---------- src/master.rs | 6 +++--- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/ethercat-sys/build.rs b/ethercat-sys/build.rs index 804a777..3527aa6 100644 --- a/ethercat-sys/build.rs +++ b/ethercat-sys/build.rs @@ -31,7 +31,7 @@ fn main() { .expect("Couldn't write bindings!"); // Generate the EC_IOCTL_ ioctl numbers -- bindgen can't handle them. - let code = fs::read_to_string(&format!("{}/master/ioctl.h", path)) + let code = fs::read_to_string(format!("{}/master/ioctl.h", path)) .expect("master/ioctl.h not found"); let mut new = String::new(); for line in code.split('\n') { diff --git a/examples/cyclic-data.rs b/examples/cyclic-data.rs index 5a2f376..065eb5e 100644 --- a/examples/cyclic-data.rs +++ b/examples/cyclic-data.rs @@ -64,17 +64,12 @@ pub fn main() -> Result<(), io::Error> { } } +type SlaveMap = HashMap>; + pub fn init_master( esi: &EtherCatInfo, idx: u32, -) -> Result< - ( - Master, - DomainIndex, - HashMap>, - ), - io::Error, -> { +) -> Result<(Master, DomainIndex, SlaveMap), io::Error> { let mut master = Master::open(idx, MasterAccess::ReadWrite)?; log::debug!("Reserve master"); master.reserve()?; @@ -111,7 +106,7 @@ pub fn init_master( sub_idx: SubIdx::from(e.sub_index.unwrap_or(1) as u8), }, bit_len: e.bit_len as u8, - name: e.name.clone().unwrap_or(String::new()), + name: e.name.clone().unwrap_or_default(), pos: PdoEntryPos::from(i as u8), }) .collect(), @@ -133,7 +128,7 @@ pub fn init_master( sub_idx: SubIdx::from(e.sub_index.unwrap_or(1) as u8), }, bit_len: e.bit_len as u8, - name: e.name.clone().unwrap_or(String::new()), + name: e.name.clone().unwrap_or_default(), pos: PdoEntryPos::from(i as u8), }) .collect(), diff --git a/src/master.rs b/src/master.rs index d84b0f4..15c7c83 100644 --- a/src/master.rs +++ b/src/master.rs @@ -89,7 +89,7 @@ impl Master { let p = self .domain_data_placement(idx) .map_err(|_| Error::NoDomain)?; - let data = self.map.as_mut().ok_or_else(|| Error::NotActivated)?; + let data = self.map.as_mut().ok_or(Error::NotActivated)?; Ok(&mut data[p.offset..p.offset + p.size]) } @@ -119,7 +119,7 @@ impl Master { .map_mut(&self.file) .map(Some)? }; - self.map.as_mut().ok_or_else(|| Error::NotActivated)?[0] = 0; + self.map.as_mut().ok_or(Error::NotActivated)?[0] = 0; Ok(()) } @@ -183,7 +183,7 @@ impl Master { app_time, .. } = data; - let first_device = devices.get(0).ok_or_else(|| Error::NoDevices)?; + let first_device = devices.first().ok_or(Error::NoDevices)?; let link_up = first_device.link_state != 0; let scan_busy = scan_busy != 0; Ok(MasterInfo {