Skip to content

Commit f1d7a5d

Browse files
committed
fix clippy warnings
1 parent 985efb4 commit f1d7a5d

File tree

6 files changed

+31
-30
lines changed

6 files changed

+31
-30
lines changed

examples/adstool.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fn main() {
319319
let args = Args::from_args();
320320

321321
if let Err(e) = main_inner(args) {
322-
eprintln!("Error: {}", e);
322+
eprintln!("Error: {e}");
323323
std::process::exit(1);
324324
}
325325
}
@@ -403,7 +403,7 @@ fn main_inner(args: Args) -> Result<(), Error> {
403403
let namelen = LE::read_u32(&routeinfo[36..]) as usize;
404404
let host = String::from_utf8_lossy(&routeinfo[44..][..hostlen - 1]);
405405
let name = String::from_utf8_lossy(&routeinfo[44 + hostlen..][..namelen - 1]);
406-
print!("{:-20} {:-22} {:-18}", name, netid, host);
406+
print!("{name:-20} {netid:-22} {host:-18}");
407407
if flags & 0x01 != 0 {
408408
print!(" temporary");
409409
}
@@ -415,7 +415,7 @@ fn main_inner(args: Args) -> Result<(), Error> {
415415
}
416416
println!();
417417
}
418-
_ => println!("Route entry {} too short", subindex),
418+
_ => println!("Route entry {subindex} too short"),
419419
}
420420
}
421421
}
@@ -459,7 +459,7 @@ fn main_inner(args: Args) -> Result<(), Error> {
459459
}
460460
}
461461
Ok(Event::Eof) => break,
462-
Err(e) => return Err(Error::Str(format!("error parsing target desc XML: {}", e))),
462+
Err(e) => return Err(Error::Str(format!("error parsing target desc XML: {e}"))),
463463
_ => (),
464464
}
465465
}
@@ -507,9 +507,9 @@ fn main_inner(args: Args) -> Result<(), Error> {
507507
let info = dev.get_info()?;
508508
println!("Device: {} {}.{}.{}", info.name, info.major, info.minor, info.version);
509509
let (state, dev_state) = dev.get_state()?;
510-
println!("Current state: {:?}", state);
510+
println!("Current state: {state:?}");
511511
if let Some(newstate) = subargs.target_state {
512-
println!("Set new state: {:?}", newstate);
512+
println!("Set new state: {newstate:?}");
513513
dev.write_control(newstate, dev_state)?;
514514
}
515515
}
@@ -553,10 +553,10 @@ fn main_inner(args: Args) -> Result<(), Error> {
553553

554554
println!("ID: {}", format_guid(guid));
555555
if let Some(exp) = exp_time {
556-
println!(" Expires: {}", exp);
556+
println!(" Expires: {exp}");
557557
}
558558
if inst_total != 0 {
559-
println!(" Instances used: {}/{}", inst_used, inst_total);
559+
println!(" Instances used: {inst_used}/{inst_total}");
560560
}
561561
}
562562
}
@@ -748,18 +748,18 @@ fn print_read_value(typ: VarType, buf: &[u8], hex: bool) {
748748
match buf[0] {
749749
0 => println!("FALSE"),
750750
1 => println!("TRUE"),
751-
n => println!("non-bool ({})", n),
751+
n => println!("non-bool ({n})"),
752752
}
753753
return;
754754
}
755755
VarType::Real => {
756756
let v = f32::from_le_bytes(buf[..4].try_into().expect("size"));
757-
println!("{}", v);
757+
println!("{v}");
758758
return;
759759
}
760760
VarType::Lreal => {
761761
let v = f64::from_le_bytes(buf[..8].try_into().expect("size"));
762-
println!("{}", v);
762+
println!("{v}");
763763
return;
764764
}
765765
VarType::Byte => buf[0] as i128,
@@ -773,9 +773,9 @@ fn print_read_value(typ: VarType, buf: &[u8], hex: bool) {
773773
};
774774
// Only reaches here for integer types
775775
if hex {
776-
println!("{:#x}", value);
776+
println!("{value:#x}");
777777
} else {
778-
println!("{}", value);
778+
println!("{value}");
779779
}
780780
}
781781

examples/notify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
std::thread::spawn(move || {
1010
for msg in recv_notify.iter() {
1111
for sample in msg.samples() {
12-
println!("notify: {:?}", sample);
12+
println!("notify: {sample:?}");
1313
}
1414
}
1515
});
@@ -39,7 +39,7 @@ fn main() {
3939
),
4040
)
4141
.unwrap();
42-
println!("{} {}", h1, h2);
42+
println!("{h1} {h2}");
4343
loop {
4444
std::thread::sleep(std::time::Duration::from_secs(1));
4545
}

src/client.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ impl Drop for Client {
149149
.get_mut()
150150
.expect("notification handle cache lock was poisoned");
151151

152-
// Remove our port from the router, if necessary.
153-
if self.source_port_opened {
154-
let mut close_port_msg = [1, 0, 2, 0, 0, 0, 0, 0];
155-
LE::write_u16(&mut close_port_msg[6..], self.source.port());
156-
157-
let _ = self.socket.write().map(|mut socket| socket.write_all(&close_port_msg));
152+
if let Ok(ref mut socket) = self.socket.write() {
153+
// Remove our port from the router, if necessary.
154+
if self.source_port_opened {
155+
let mut close_port_msg = [1, 0, 2, 0, 0, 0, 0, 0];
156+
LE::write_u16(&mut close_port_msg[6..], self.source.port());
157+
let _ = socket.write_all(&close_port_msg);
158+
}
158159
}
159160

160161
self.worker.stop();
@@ -482,14 +483,14 @@ impl ClientWorker {
482483

483484
let _ = socket.shutdown(Shutdown::Both);
484485

485-
let _ = pending.write().map(|mut pending| {
486+
if let Ok(ref mut pending) = pending.write() {
486487
let keys = pending.keys().cloned().collect_vec();
487488
for key in keys {
488489
if let Some(channel) = pending.remove(&key) {
489490
let _ = channel.send(None);
490491
};
491492
}
492-
});
493+
}
493494

494495
result
495496
});

src/notif.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl std::fmt::Debug for Notification {
6161
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6262
writeln!(f, "Notification [")?;
6363
for sample in self.samples() {
64-
writeln!(f, " {:?}", sample)?;
64+
writeln!(f, " {sample:?}")?;
6565
}
6666
write!(f, "]")
6767
}

src/test/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl Server {
9292
}
9393
panic!("unexpected receive error: {}", e);
9494
}
95-
println!(">>> {:?}", header);
95+
println!(">>> {header:?}");
9696
let mut data = vec![0; header.data_length.get() as usize];
9797
socket.read_exact(&mut data).unwrap();
9898

@@ -133,7 +133,7 @@ impl Server {
133133
if !opts.ignore_invokeid {
134134
reply_header.invoke_id = header.invoke_id;
135135
}
136-
println!("<<< {:?}", reply_header);
136+
println!("<<< {reply_header:?}");
137137

138138
socket.write_all(reply_header.as_bytes()).unwrap();
139139
socket.write_all(&reply_data).unwrap();
@@ -162,7 +162,7 @@ impl Server {
162162
ads_header.command.set(crate::client::Command::Notification as u16);
163163
ads_header.state_flags.set(4);
164164
ads_header.data_length.set(data_len as u32);
165-
println!("not: {:?}", ads_header);
165+
println!("not: {ads_header:?}");
166166

167167
socket.write_all(ads_header.as_bytes()).unwrap();
168168
socket.write_all(notif_header.as_bytes()).unwrap();

src/test/test_client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn test_notification() {
182182
let first = chan.try_recv().unwrap();
183183
let second = chan.try_recv().unwrap();
184184

185-
println!("{:?}", first);
185+
println!("{first:?}");
186186

187187
let mut samples = first.samples();
188188
assert_eq!(
@@ -265,7 +265,7 @@ fn test_string_type() {
265265
assert!(<[u8; 5]>::from(bstr2) == [b'a', b'b', b'c', 0, 0]);
266266
assert!(bstr == bstr2);
267267

268-
assert!(format!("{:?}", bstr) == "\"abc\"");
268+
assert!(format!("{bstr:?}") == "\"abc\"");
269269

270270
device.write_value(0x4020, 7, &bstr).unwrap();
271271

@@ -291,7 +291,7 @@ fn test_wstring_type() {
291291
assert!(WString5::try_from(&[1, 2, 3, 4, 5, 6][..]).is_err());
292292
assert!(WString5::try_from("abcdef").is_err());
293293

294-
assert!(format!("{:?}", wstr) == "\"abc\"");
294+
assert!(format!("{wstr:?}") == "\"abc\"");
295295

296296
let wstr2 = WString5::try_from(&[b'a' as u16, b'b' as u16, b'c' as u16][..]).unwrap();
297297
assert!(<[u16; 5]>::from(wstr2) == [b'a' as u16, b'b' as u16, b'c' as u16, 0, 0]);

0 commit comments

Comments
 (0)