From 0b3af8aed201cd5ad2e9c6aedd89852d5267675d Mon Sep 17 00:00:00 2001 From: Henry Hrvoje Tonkovac Date: Sat, 6 Jun 2026 20:43:35 +0200 Subject: [PATCH] net_util: trim qualified paths Import the std modules used across the crate instead of spelling the full paths at every use site. Signed-off-by: Henry Hrvoje Tonkovac Assisted-by: Claude:Opus-4.8 --- net_util/src/ctrl_queue.rs | 4 +++- net_util/src/lib.rs | 10 +++++----- net_util/src/mac.rs | 2 +- net_util/src/open_tap.rs | 6 +++--- net_util/src/queue_pair.rs | 13 +++++++------ net_util/src/tap.rs | 12 +++++------- 6 files changed, 24 insertions(+), 23 deletions(-) diff --git a/net_util/src/ctrl_queue.rs b/net_util/src/ctrl_queue.rs index 8b34a33a7..28b41c238 100644 --- a/net_util/src/ctrl_queue.rs +++ b/net_util/src/ctrl_queue.rs @@ -2,6 +2,8 @@ // // SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause +use std::result; + use log::{debug, error, info, warn}; use thiserror::Error; use virtio_bindings::virtio_net::{ @@ -45,7 +47,7 @@ pub enum Error { QueueEnableNotification(#[source] virtio_queue::Error), } -type Result = std::result::Result; +type Result = result::Result; #[repr(C, packed)] #[derive(Debug, Clone, Copy, Default)] diff --git a/net_util/src/lib.rs b/net_util/src/lib.rs index 7152c1676..f81334a2e 100644 --- a/net_util/src/lib.rs +++ b/net_util/src/lib.rs @@ -15,7 +15,7 @@ use std::io::Error as IoError; use std::net::IpAddr; use std::os::raw::c_uint; use std::os::unix::io::{FromRawFd, RawFd}; -use std::{io, mem, net}; +use std::{io, mem, net, result}; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -41,7 +41,7 @@ pub enum Error { CreateSocket(#[source] IoError), } -pub type Result = std::result::Result; +pub type Result = result::Result; #[repr(C, packed)] #[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] @@ -102,7 +102,7 @@ fn create_unix_socket() -> Result { } fn vnet_hdr_len() -> usize { - std::mem::size_of::() + mem::size_of::() } pub fn register_listener( @@ -110,7 +110,7 @@ pub fn register_listener( fd: RawFd, ev_type: epoll::Events, data: u64, -) -> std::result::Result<(), io::Error> { +) -> io::Result<()> { epoll::ctl( epoll_fd, epoll::ControlOptions::EPOLL_CTL_ADD, @@ -124,7 +124,7 @@ pub fn unregister_listener( fd: RawFd, ev_type: epoll::Events, data: u64, -) -> std::result::Result<(), io::Error> { +) -> io::Result<()> { epoll::ctl( epoll_fd, epoll::ControlOptions::EPOLL_CTL_DEL, diff --git a/net_util/src/mac.rs b/net_util/src/mac.rs index d9501a1d9..cf9cf6a87 100644 --- a/net_util/src/mac.rs +++ b/net_util/src/mac.rs @@ -131,7 +131,7 @@ pub enum MacAddrParseError { impl FromStr for MacAddr { type Err = MacAddrParseError; - fn from_str(s: &str) -> std::result::Result { + fn from_str(s: &str) -> Result { MacAddr::parse_str(s).map_err(|_| MacAddrParseError::InvalidValue(s.to_owned())) } } diff --git a/net_util/src/open_tap.rs b/net_util/src/open_tap.rs index a5168d22a..6cc8b2a37 100644 --- a/net_util/src/open_tap.rs +++ b/net_util/src/open_tap.rs @@ -4,7 +4,7 @@ use std::net::IpAddr; use std::path::Path; -use std::{fs, io}; +use std::{fs, io, num, result}; use log::warn; use thiserror::Error; @@ -14,7 +14,7 @@ use super::{MacAddr, Tap, TapError, vnet_hdr_len}; #[derive(Error, Debug)] pub enum Error { #[error("Failed to convert an hexadecimal string into an integer")] - ConvertHexStringToInt(#[source] std::num::ParseIntError), + ConvertHexStringToInt(#[source] num::ParseIntError), #[error("Error related to the multiqueue support (no support TAP side)")] MultiQueueNoTapSupport, #[error("Error related to the multiqueue support (no support device side)")] @@ -37,7 +37,7 @@ pub enum Error { TapEnable(#[source] TapError), } -type Result = std::result::Result; +type Result = result::Result; fn check_mq_support(if_name: &Option<&str>, queue_pairs: usize) -> Result<()> { if let Some(tap_name) = if_name { diff --git a/net_util/src/queue_pair.rs b/net_util/src/queue_pair.rs index 337d64c1e..242beaaff 100644 --- a/net_util/src/queue_pair.rs +++ b/net_util/src/queue_pair.rs @@ -4,6 +4,7 @@ use std::io; use std::num::Wrapping; +use std::ops::{Deref, DerefMut}; use std::os::unix::io::{AsRawFd, RawFd}; use std::sync::Arc; use std::sync::atomic::{AtomicU64, Ordering}; @@ -125,10 +126,10 @@ impl TxVirtio { }; if result < 0 { - let e = std::io::Error::last_os_error(); + let e = io::Error::last_os_error(); /* EAGAIN */ - if e.kind() == std::io::ErrorKind::WouldBlock { + if e.kind() == io::ErrorKind::WouldBlock { queue.go_to_previous_position(); retry_write = true; break; @@ -304,10 +305,10 @@ impl RxVirtio { ) }; if result < 0 { - let e = std::io::Error::last_os_error(); + let e = io::Error::last_os_error(); /* EAGAIN */ - if e.kind() == std::io::ErrorKind::WouldBlock { + if e.kind() == io::ErrorKind::WouldBlock { exhausted_descs = false; queue.go_to_previous_position(); break; @@ -405,7 +406,7 @@ impl IovecBuffer { struct IovecBufferBorrowed<'a>(&'a mut Vec); -impl std::ops::Deref for IovecBufferBorrowed<'_> { +impl Deref for IovecBufferBorrowed<'_> { type Target = Vec; fn deref(&self) -> &Self::Target { @@ -413,7 +414,7 @@ impl std::ops::Deref for IovecBufferBorrowed<'_> { } } -impl std::ops::DerefMut for IovecBufferBorrowed<'_> { +impl DerefMut for IovecBufferBorrowed<'_> { fn deref_mut(&mut self) -> &mut Self::Target { self.0 } diff --git a/net_util/src/tap.rs b/net_util/src/tap.rs index 6ec4f0ca7..a06b12fde 100644 --- a/net_util/src/tap.rs +++ b/net_util/src/tap.rs @@ -11,6 +11,7 @@ use std::io::{Error as IoError, Read, Result as IoResult, Write}; use std::net::{IpAddr, Ipv6Addr}; use std::os::raw::*; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; +use std::{mem, result, str}; use libc::{__c_anonymous_ifr_ifru, IFNAMSIZ, ifreq}; use thiserror::Error; @@ -48,7 +49,7 @@ pub enum Error { InvalidNetmask, } -pub type Result = ::std::result::Result; +pub type Result = result::Result; /// Handle for a network tap interface. /// @@ -69,7 +70,7 @@ impl PartialEq for Tap { } } -impl std::clone::Clone for Tap { +impl Clone for Tap { fn clone(&self) -> Self { Tap { tap_file: self.tap_file.try_clone().unwrap(), @@ -342,9 +343,7 @@ impl Tap { let ifreq = libc::in6_ifreq { // SAFETY: addr can be safely transmuted to in6_addr - ifr6_addr: unsafe { - std::mem::transmute::<[u8; 16], libc::in6_addr>(addr.octets()) - }, + ifr6_addr: unsafe { mem::transmute::<[u8; 16], libc::in6_addr>(addr.octets()) }, ifr6_prefixlen: prefixlen as u32, ifr6_ifindex: ifindex, }; @@ -512,8 +511,7 @@ impl Tap { /// also always created from Rust strings, thus valid UTF-8. pub fn if_name_as_str(&self) -> &str { // Panicking here is fine, see function documentation. - std::str::from_utf8(self.if_name.as_bytes()) - .expect("Tap interface name should be valid UTF-8") + str::from_utf8(self.if_name.as_bytes()).expect("Tap interface name should be valid UTF-8") } #[cfg(fuzzing)]