Skip to content

Commit

Permalink
all: clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
birkenfeld committed Aug 10, 2024
1 parent 797cbab commit 34056fa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ethercat-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
15 changes: 5 additions & 10 deletions examples/cyclic-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,12 @@ pub fn main() -> Result<(), io::Error> {
}
}

type SlaveMap = HashMap<SlavePos, HashMap<PdoEntryIndex, (BitLen, Offset)>>;

pub fn init_master(
esi: &EtherCatInfo,
idx: u32,
) -> Result<
(
Master,
DomainIndex,
HashMap<SlavePos, HashMap<PdoEntryIndex, (BitLen, Offset)>>,
),
io::Error,
> {
) -> Result<(Master, DomainIndex, SlaveMap), io::Error> {
let mut master = Master::open(idx, MasterAccess::ReadWrite)?;
log::debug!("Reserve master");
master.reserve()?;
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
6 changes: 3 additions & 3 deletions src/master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}

Expand Down Expand Up @@ -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(())
}

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 34056fa

Please sign in to comment.