Skip to content

Commit 143b904

Browse files
committed
clippy fixes
Signed-off-by: Janne Grunau <[email protected]>
1 parent 2e300f3 commit 143b904

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/cd321x.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn verify_i2c_device(bus: &str, slave_address: u16) -> Result<LinuxI2CDevice> {
7979
let forced = unsafe { LinuxI2CDevice::force_new(bus, slave_address) };
8080
match forced {
8181
Ok(dev) => Ok(dev),
82-
Err(_) => Err(Error::I2CError),
82+
Err(_) => Err(Error::I2C),
8383
}
8484
}
8585

@@ -152,16 +152,14 @@ impl Device {
152152
buf.push(reg);
153153
buf.push(size);
154154
buf.extend_from_slice(data);
155-
self.i2c.write(&buf).map_err(|_| Error::I2CError)?;
155+
self.i2c.write(&buf).map_err(|_| Error::I2C)?;
156156
Ok(())
157157
}
158158

159159
fn read_block(&mut self, reg: u8, buf: &mut [u8]) -> Result<()> {
160-
self.i2c.write(&[reg]).map_err(|_| Error::I2CError)?;
160+
self.i2c.write(&[reg]).map_err(|_| Error::I2C)?;
161161
let mut internal_buf = vec![0u8; buf.len() + 1];
162-
self.i2c
163-
.read(&mut internal_buf)
164-
.map_err(|_| Error::I2CError)?;
162+
self.i2c.read(&mut internal_buf).map_err(|_| Error::I2C)?;
165163
buf.copy_from_slice(&internal_buf[1..=buf.len()]);
166164

167165
Ok(())
@@ -176,7 +174,7 @@ impl Device {
176174
}
177175

178176
fn lock(&mut self, key: &[u8]) -> Result<()> {
179-
self.exec_cmd(b"LOCK", &key)
177+
self.exec_cmd(b"LOCK", key)
180178
}
181179

182180
fn dbma(&mut self, debug: bool) -> Result<()> {

src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ enum Error {
2020
InvalidArgument,
2121
ReconnectTimeout,
2222
ControllerTimeout,
23-
I2CError,
23+
I2C,
2424
Io(std::io::Error),
2525
Utf8(std::str::Utf8Error),
26+
Parse(std::num::ParseIntError),
2627
}
2728

2829
type Result<T> = std::result::Result<T, Error>;
@@ -64,10 +65,10 @@ fn vdmtool() -> Result<()> {
6465

6566
let addr_str = matches.get_one::<String>("address").unwrap();
6667
let addr: u16;
67-
if addr_str.starts_with("0x") {
68-
addr = u16::from_str_radix(&addr_str[2..], 16).unwrap();
68+
if let Some(stripped) = addr_str.strip_prefix("0x") {
69+
addr = u16::from_str_radix(stripped, 16).map_err(Error::Parse)?;
6970
} else {
70-
addr = u16::from_str_radix(addr_str, 10).unwrap();
71+
addr = addr_str.parse::<u16>().map_err(Error::Parse)?;
7172
}
7273

7374
let code = device.to_uppercase();

0 commit comments

Comments
 (0)