From 61ed6d62c4b98a0959bc85618f0be6e45769483a Mon Sep 17 00:00:00 2001 From: ssrlive <30760636+ssrlive@users.noreply.github.com> Date: Mon, 1 Jan 2024 14:40:50 +0800 Subject: [PATCH] clippy issues --- .github/workflows/format-build.yml | 4 ++++ src/dns.rs | 2 +- src/virtdns.rs | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/format-build.yml b/.github/workflows/format-build.yml index 9469bf9..c45afe6 100644 --- a/.github/workflows/format-build.yml +++ b/.github/workflows/format-build.yml @@ -46,6 +46,10 @@ jobs: profile: minimal toolchain: stable override: true + - name: rustfmt + run: | + rustc --version + cargo fmt --all -- --check - run: rustup component add clippy - uses: actions-rs/cargo@v1 with: diff --git a/src/dns.rs b/src/dns.rs index 1d9ee61..2f95b22 100644 --- a/src/dns.rs +++ b/src/dns.rs @@ -88,7 +88,7 @@ pub fn extract_ipaddr_from_dns_message(message: &Message) -> Result Result { - let query = message.queries().get(0).ok_or("DnsRequest no query body")?; + let query = message.queries().first().ok_or("DnsRequest no query body")?; let name = query.name().to_string(); Ok(name) } diff --git a/src/virtdns.rs b/src/virtdns.rs index eaed24b..01f4363 100644 --- a/src/virtdns.rs +++ b/src/virtdns.rs @@ -5,7 +5,7 @@ use hashlink::{linked_hash_map::RawEntryMut, LruCache}; use smoltcp::wire::Ipv4Cidr; use std::{ collections::HashMap, - convert::{TryFrom, TryInto}, + convert::TryInto, net::{IpAddr, Ipv4Addr, Ipv6Addr}, str::FromStr, time::{Duration, Instant}, @@ -34,8 +34,8 @@ impl Default for VirtualDns { Self { next_addr: start_addr.into(), name_to_ip: HashMap::default(), - network_addr: IpAddr::try_from(cidr.network().address().into_address()).unwrap(), - broadcast_addr: IpAddr::try_from(cidr.broadcast().unwrap().into_address()).unwrap(), + network_addr: IpAddr::from(cidr.network().address().into_address()), + broadcast_addr: IpAddr::from(cidr.broadcast().unwrap().into_address()), lru_cache: LruCache::new_unbounded(), } }