From b8be33dff7694f983ac3d1eafc75c1065eb691c6 Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Tue, 17 Jun 2025 12:37:13 +0200 Subject: [PATCH] net_util: tap: remove needless copy One can call `to_vec()` anyway if one needs an owned copy. This change further helps to prevent needless copies in upcoming changes. Signed-off-by: Philipp Schuster On-behalf-of: SAP philipp.schuster@sap.com --- net_util/src/open_tap.rs | 2 +- net_util/src/tap.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net_util/src/open_tap.rs b/net_util/src/open_tap.rs index e711529ca..e02e3b5e8 100644 --- a/net_util/src/open_tap.rs +++ b/net_util/src/open_tap.rs @@ -135,7 +135,7 @@ pub fn open_tap( // same device. tap = open_tap_rx_q_0(if_name, ip_addr, netmask, host_mac, mtu, num_rx_q, flags)?; // Set the name of the tap device we open in subsequent iterations. - ifname = String::from_utf8(tap.get_if_name()).unwrap(); + ifname = String::from_utf8(tap.get_if_name().to_vec()).unwrap(); } else { tap = Tap::open_named(ifname.as_str(), num_rx_q, flags).map_err(Error::TapOpen)?; diff --git a/net_util/src/tap.rs b/net_util/src/tap.rs index 1dc0b7f48..bc841de11 100644 --- a/net_util/src/tap.rs +++ b/net_util/src/tap.rs @@ -481,8 +481,8 @@ impl Tap { ifreq } - pub fn get_if_name(&self) -> Vec { - self.if_name.clone() + pub fn get_if_name(&self) -> &[u8] { + &self.if_name } #[cfg(fuzzing)]