clippy all codes (#1214)

1. clippy code
2. add fmt and clippy check in ci
This commit is contained in:
Sijie.Sun
2025-08-10 22:56:41 +08:00
committed by GitHub
parent 0087ac3ffc
commit e43537939a
144 changed files with 1475 additions and 1531 deletions

View File

@@ -17,11 +17,17 @@ pub struct ChannelDevice {
caps: DeviceCapabilities,
}
pub type ChannelDeviceNewRet = (
ChannelDevice,
Sender<io::Result<Vec<u8>>>,
Receiver<Vec<u8>>,
);
impl ChannelDevice {
/// Make a new `ChannelDevice` with the given `recv` and `send` channels.
///
/// The `caps` is used to determine the device capabilities. `DeviceCapabilities::max_transmission_unit` must be set.
pub fn new(caps: DeviceCapabilities) -> (Self, Sender<io::Result<Vec<u8>>>, Receiver<Vec<u8>>) {
pub fn new(caps: DeviceCapabilities) -> ChannelDeviceNewRet {
let (tx1, rx1) = channel(1000);
let (tx2, rx2) = channel(1000);
(
@@ -45,7 +51,7 @@ impl Stream for ChannelDevice {
}
fn map_err(e: PollSendError<Vec<u8>>) -> io::Error {
io::Error::new(io::ErrorKind::Other, e)
io::Error::other(e)
}
impl Sink<Vec<u8>> for ChannelDevice {

View File

@@ -46,8 +46,8 @@ impl RxToken for BufferRxToken {
F: FnOnce(&[u8]) -> R,
{
let p = &mut self.0;
let result = f(p);
result
f(p)
}
}
@@ -79,10 +79,9 @@ impl Device for BufferDevice {
Self: 'a;
fn receive(&mut self, _timestamp: Instant) -> Option<(Self::RxToken<'_>, Self::TxToken<'_>)> {
match self.recv_queue.pop_front() {
Some(p) => Some((BufferRxToken(p), BufferTxToken(self))),
None => None,
}
self.recv_queue
.pop_front()
.map(|p| (BufferRxToken(p), BufferTxToken(self)))
}
fn transmit(&mut self, _timestamp: Instant) -> Option<Self::TxToken<'_>> {

View File

@@ -4,7 +4,7 @@
use std::{
io,
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
net::{IpAddr, SocketAddr},
sync::{
atomic::{AtomicU16, Ordering},
Arc,
@@ -34,7 +34,7 @@ mod socket_allocator;
/// Can be used to create a forever timestamp in neighbor.
// The 60_000 is the same as NeighborCache::ENTRY_LIFETIME.
pub const FOREVER: Instant =
Instant::from_micros_const(i64::max_value() - Duration::from_millis(60_000).micros() as i64);
Instant::from_micros_const(i64::MAX - Duration::from_millis(60_000).micros() as i64);
pub struct Neighbor {
pub protocol_addr: IpAddress,
@@ -173,8 +173,8 @@ impl Net {
fn set_address(&self, mut addr: SocketAddr) -> SocketAddr {
if addr.ip().is_unspecified() {
addr.set_ip(match self.ip_addr.address() {
IpAddress::Ipv4(ip) => Ipv4Addr::from(ip).into(),
IpAddress::Ipv6(ip) => Ipv6Addr::from(ip).into(),
IpAddress::Ipv4(ip) => ip.into(),
IpAddress::Ipv6(ip) => ip.into(),
#[allow(unreachable_patterns)]
_ => panic!("address must not be unspecified"),
});

View File

@@ -51,9 +51,7 @@ async fn run(
loop {
let packets = device.take_send_queue();
async_iface
.send_all(&mut iter(packets).map(|p| Ok(p)))
.await?;
async_iface.send_all(&mut iter(packets).map(Ok)).await?;
if recv_buf.is_empty() && device.need_wait() {
let start = Instant::now();
@@ -94,14 +92,10 @@ async fn run(
// wake up all closed sockets (smoltcp seems have a bug that it doesn't wake up closed sockets)
for (_, socket) in socket_allocator.sockets().lock().iter_mut() {
match socket {
Socket::Tcp(tcp) => {
if tcp.state() == smoltcp::socket::tcp::State::Closed {
tcp.abort();
}
if let Socket::Tcp(tcp) = socket {
if tcp.state() == smoltcp::socket::tcp::State::Closed {
tcp.abort();
}
#[allow(unreachable_patterns)]
_ => {}
}
}
}
@@ -164,10 +158,8 @@ impl Reactor {
impl Drop for Reactor {
fn drop(&mut self) {
for (_, socket) in self.socket_allocator.sockets().lock().iter_mut() {
match socket {
Socket::Tcp(tcp) => tcp.close(),
#[allow(unreachable_patterns)]
_ => {}
if let Socket::Tcp(tcp) = socket {
tcp.close()
}
}
}

View File

@@ -5,7 +5,7 @@ pub use smoltcp::socket::tcp;
use smoltcp::socket::udp;
use smoltcp::wire::{IpAddress, IpEndpoint};
use std::mem::replace;
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::net::IpAddr;
use std::{
io,
net::SocketAddr,
@@ -25,7 +25,7 @@ pub struct TcpListener {
}
fn map_err<E: std::error::Error>(e: E) -> io::Error {
io::Error::new(io::ErrorKind::Other, e.to_string())
io::Error::other(e.to_string())
}
impl TcpListener {
@@ -95,8 +95,8 @@ impl Stream for Incoming {
fn ep2sa(ep: &IpEndpoint) -> SocketAddr {
match ep.addr {
IpAddress::Ipv4(v4) => SocketAddr::new(IpAddr::V4(Ipv4Addr::from(v4)), ep.port),
IpAddress::Ipv6(v6) => SocketAddr::new(IpAddr::V6(Ipv6Addr::from(v6)), ep.port),
IpAddress::Ipv4(v4) => SocketAddr::new(IpAddr::V4(v4), ep.port),
IpAddress::Ipv6(v6) => SocketAddr::new(IpAddr::V6(v6), ep.port),
#[allow(unreachable_patterns)]
_ => unreachable!(),
}