Skip to content

Commit 1078999

Browse files
committed
Fix clippy warnings
Fix warnings produced by cargo clippy --all-targets
1 parent 06bef46 commit 1078999

File tree

15 files changed

+61
-57
lines changed

15 files changed

+61
-57
lines changed

.github/workflows/rust_stable.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ jobs:
2121
- uses: sensorfu/setup-rust-action@v1
2222
with:
2323
components: clippy,rustfmt
24-
- run: cargo clippy -- -D warnings
24+
- run: cargo clippy -- -D warnings --all-targets
2525
- run: cargo fmt --all -- --check

luomu-common/src/addr_pair.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ mod tests {
446446
}
447447

448448
#[test]
449-
#[should_panic]
449+
#[should_panic(
450+
expected = "IPPair::new() invalid IP address families provided. src: Source(192.0.2.5), dst: Destination(2001:db8:42::12:765)"
451+
)]
450452
fn test_ip_pair_fail() {
451453
let ip1: IpAddr = "192.0.2.5".parse().unwrap();
452454
let ip2: IpAddr = "2001:db8:42::12:765".parse().unwrap();

luomu-common/src/ipaddr.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ mod tests {
204204

205205
// 0.0.0.0/32 "This host on this network" [RFC1122], Section 3.2.1.3
206206
// 0.0.0.0/8 "This network" [RFC791], Section 3.2
207-
const V4_THIS_NETWORK: &[Ipv4Addr] = &[Ipv4Addr::new(0, 0, 0, 0), Ipv4Addr::new(0, 255, 255, 255)];
207+
const V4_THIS_NETWORK: &[Ipv4Addr] = &[Ipv4Addr::UNSPECIFIED, Ipv4Addr::new(0, 255, 255, 255)];
208208

209209
// 127.0.0.0/8 Loopback [RFC1122] Section 3.2.1.3
210210
const V4_LOOPBACKS: &[Ipv4Addr] = &[
211211
Ipv4Addr::new(127, 0, 0, 0),
212-
Ipv4Addr::new(127, 0, 0, 1),
212+
Ipv4Addr::LOCALHOST,
213213
Ipv4Addr::new(127, 255, 255, 255),
214214
];
215215

@@ -240,7 +240,7 @@ mod tests {
240240
Ipv4Addr::new(240, 0, 0, 0),
241241
Ipv4Addr::new(254, 255, 255, 255),
242242
Ipv4Addr::new(255, 0, 0, 0),
243-
Ipv4Addr::new(255, 255, 255, 255),
243+
Ipv4Addr::BROADCAST,
244244
];
245245

246246
// ::ffff:0:0/96 IPv4-mapped Address [RFC4291]
@@ -270,7 +270,7 @@ mod tests {
270270
.chain(V4_IETF_PROTOCOL_ASSIGNMENTS)
271271
.chain(V4_DOCUMENTATION)
272272
.chain(V4_RESERVED)
273-
.cloned()
273+
.copied()
274274
}
275275

276276
fn yield_invalid_destination_ip4() -> impl Iterator<Item = Ipv4Addr> {
@@ -281,7 +281,7 @@ mod tests {
281281
.chain(V4_DOCUMENTATION)
282282
.chain(V4_RESERVED)
283283
.filter(|ip| **ip != Ipv4Addr::BROADCAST)
284-
.cloned()
284+
.copied()
285285
}
286286

287287
fn yield_invalid_forwardable_ip4() -> impl Iterator<Item = Ipv4Addr> {
@@ -293,25 +293,25 @@ mod tests {
293293

294294
// If the value of "Destination" is FALSE, the values of "Forwardable"
295295
// and "Globally Reachable" must also be false.
296-
yield_invalid_destination_ip4().chain(OTHERS.iter().cloned())
296+
yield_invalid_destination_ip4().chain(OTHERS.iter().copied())
297297
}
298298

299299
fn yield_invalid_source_ip6() -> impl Iterator<Item = Ipv6Addr> {
300300
const OTHERS: &[Ipv6Addr] = &[Ipv6Addr::LOCALHOST];
301301

302-
V6_V4_MAPPED.iter().chain(V6_DOCUMENTATION).chain(OTHERS).cloned()
302+
V6_V4_MAPPED.iter().chain(V6_DOCUMENTATION).chain(OTHERS).copied()
303303
}
304304

305305
fn yield_invalid_destination_ip6() -> impl Iterator<Item = Ipv6Addr> {
306306
const OTHERS: &[Ipv6Addr] = &[Ipv6Addr::UNSPECIFIED, Ipv6Addr::LOCALHOST];
307307

308-
V6_V4_MAPPED.iter().chain(V6_DOCUMENTATION).chain(OTHERS).cloned()
308+
V6_V4_MAPPED.iter().chain(V6_DOCUMENTATION).chain(OTHERS).copied()
309309
}
310310

311311
fn yield_invalid_forwardable_ip6() -> impl Iterator<Item = Ipv6Addr> {
312312
// If the value of "Destination" is FALSE, the values of "Forwardable"
313313
// and "Globally Reachable" must also be false.
314-
yield_invalid_destination_ip6().chain(V6_LINK_LOCAL_UNICAST.iter().cloned())
314+
yield_invalid_destination_ip6().chain(V6_LINK_LOCAL_UNICAST.iter().copied())
315315
}
316316

317317
fn yield_valid_ip4() -> impl Iterator<Item = Ipv4Addr> {

luomu-common/src/macaddr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ mod tests {
305305
#[test]
306306
fn test_fmt_debug() {
307307
let mac: MacAddr = [0x00, 0xff, 0x11, 0xee, 0x22, 0xdd].into();
308-
let debug = format!("{:?}", mac);
308+
let debug = format!("{mac:?}");
309309
assert_eq!(&debug, "MacAddr(00:ff:11:ee:22:dd)");
310310
}
311311

@@ -319,22 +319,22 @@ mod tests {
319319

320320
#[test]
321321
fn test_try_from_u64_bounds() {
322-
let i0 = 0x0000000000000000;
322+
let i0 = 0x0000_0000_0000_0000;
323323
assert!(MacAddr::try_from(i0).is_ok());
324324

325-
let i1 = 0x0000FFFFFFFFFFFF;
325+
let i1 = 0x0000_FFFF_FFFF_FFFF;
326326
assert!(MacAddr::try_from(i1).is_ok());
327327

328-
let i2 = 0x0001000000000000;
328+
let i2 = 0x0001_0000_0000_0000;
329329
assert!(MacAddr::try_from(i2).is_err());
330330

331-
let i3 = 0xFFFFFFFFFFFFFFFF;
331+
let i3 = 0xFFFF_FFFF_FFFF_FFFF;
332332
assert!(MacAddr::try_from(i3).is_err());
333333
}
334334

335335
#[test]
336336
fn test_try_from_u64_byteoder() {
337-
let i = 0x0000123456789ABC;
337+
let i = 0x0000_1234_5678_9ABC;
338338
let mac = MacAddr::try_from(i).unwrap();
339339
let b: [u8; 6] = mac.as_array();
340340
assert_eq!(&b, &[0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC]);
@@ -429,7 +429,7 @@ mod tests {
429429
addr2.push_tag(1337).unwrap();
430430
addr3.push_tag(42).unwrap();
431431

432-
let mut v = vec![addr1, addr2, addr3];
432+
let mut v = [addr1, addr2, addr3];
433433
v.sort();
434434

435435
assert_eq!(v[0], addr3);

luomu-common/src/tagged_macaddr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ mod tests {
209209
let mac: MacAddr = "11:22:33:AA:BB:CC".parse().unwrap();
210210
let tagged_mac: TaggedMacAddr = mac.into();
211211

212-
assert_eq!(tagged_mac.mac().is_unspecified(), false);
212+
assert!(!tagged_mac.mac().is_unspecified());
213213
}
214214

215215
#[test]
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! List all interfaces and their information
22
33
fn main() -> std::io::Result<()> {
4-
luomu_getifaddrs::getifaddrs()?
5-
.into_iter()
6-
.for_each(|ifaddr| println!("{:#?}", ifaddr.ifaddress()));
4+
luomu_getifaddrs::getifaddrs()?.for_each(|ifaddr| println!("{:#?}", ifaddr.ifaddress()));
75
Ok(())
86
}

luomu-getifaddrs/examples/ipaddresses.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() -> std::io::Result<()> {
1717
.collect::<Box<[String]>>()
1818
.join(", ");
1919

20-
println!("{name}: {addrs_text}")
20+
println!("{name}: {addrs_text}");
2121
}
2222

2323
Ok(())

luomu-libpcap/examples/capture.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(missing_docs)]
2-
32
use luomu_libpcap::{Packet, Pcap, Result};
3+
use std::fmt::Write;
44

55
fn main() -> Result<()> {
66
tracing_subscriber::fmt::init();
@@ -26,20 +26,21 @@ fn main() -> Result<()> {
2626
if i % 32 == 0 {
2727
hex.push('\n');
2828
}
29-
hex.push_str(&format!("{:02x}", packet[i]));
29+
let _ = write!(hex, "{:02x}", packet[i]);
3030
}
3131
count += 1;
32-
println!("{}", hex);
32+
println!("{hex}");
3333
hex.clear();
34-
if count % 100 == 0 && count != 0 {
35-
if let Ok(stats) = pcap.stats() {
36-
println!(
37-
"\nStats: received: {} packets, dropped: {} packets, dropped on interface {} packets",
38-
stats.packets_received(),
39-
stats.packets_dropped(),
40-
stats.packets_dropped_interface()
41-
);
42-
}
34+
if count % 100 == 0
35+
&& count != 0
36+
&& let Ok(stats) = pcap.stats()
37+
{
38+
println!(
39+
"\nStats: received: {} packets, dropped: {} packets, dropped on interface {} packets",
40+
stats.packets_received(),
41+
stats.packets_dropped(),
42+
stats.packets_dropped_interface()
43+
);
4344
}
4445
}
4546
}

luomu-libpcap/examples/list-ifs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn main() -> Result<()> {
77

88
let pcap_ifs = PcapIfT::new()?;
99
for interface in pcap_ifs.get_interfaces() {
10-
println!("{:#?}", interface);
10+
println!("{interface:#?}");
1111
}
1212

1313
Ok(())

luomu-libpcap/examples/offline.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
#![allow(missing_docs)]
22

33
use std::env;
4+
use std::fmt::Write;
45

56
use luomu_libpcap::{Packet, Pcap};
67

78
fn main() {
89
tracing_subscriber::fmt::init();
910

10-
let fname = match env::args().nth(1) {
11-
None => {
12-
tracing::error!("No PCAP file name given");
13-
return;
14-
}
15-
Some(n) => n,
11+
let Some(fname) = env::args().nth(1) else {
12+
tracing::error!("No PCAP file name given");
13+
return;
1614
};
1715

1816
let pcap = Pcap::offline(&fname).unwrap();
@@ -26,7 +24,7 @@ fn main() {
2624
if i % 32 == 0 {
2725
hex.push('\n');
2826
}
29-
hex.push_str(&format!("{:02x}", packet[i]));
27+
let _ = write!(hex, "{:02x}", packet[i]);
3028
}
3129
println!("Packet {} ({} bytes): {}", count + 1, packet.len(), hex);
3230
}

0 commit comments

Comments
 (0)