From 3cb97d237324e719f02ccde5e3fafd5d9339b699 Mon Sep 17 00:00:00 2001 From: Josh Wu Date: Wed, 2 Jul 2025 12:32:41 +0800 Subject: [PATCH] Fix Rust linter errors --- rust/examples/scanner.rs | 4 ++-- rust/src/adv.rs | 18 +++++++++--------- rust/src/cli/l2cap/client_bridge.rs | 6 +++--- rust/src/cli/l2cap/mod.rs | 2 +- rust/src/cli/l2cap/server_bridge.rs | 2 +- rust/src/cli/usb/mod.rs | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/rust/examples/scanner.rs b/rust/examples/scanner.rs index 0880e25..a146e32 100644 --- a/rust/examples/scanner.rs +++ b/rust/examples/scanner.rs @@ -127,7 +127,7 @@ async fn main() -> PyResult<()> { } else { matching .iter() - .map(|t| format!("{}", t)) + .map(|t| format!("{t}")) .join(" / ") .blue() .to_string() @@ -148,7 +148,7 @@ async fn main() -> PyResult<()> { .next() .unwrap_or_else(|| format!("0x{}", hex::encode_upper(&data))); - println!(" [{}]: {}", code_str, data_str) + println!(" [{code_str}]: {data_str}") }); Ok(()) diff --git a/rust/src/adv.rs b/rust/src/adv.rs index 6f84cc5..1d257bf 100644 --- a/rust/src/adv.rs +++ b/rust/src/adv.rs @@ -163,7 +163,7 @@ impl CommonDataType { /// Apply type-specific human-oriented formatting to data, if any is applicable pub fn format_data(&self, data: &[u8]) -> Option { match self { - Self::Flags => Some(Flags::matching(data).map(|f| format!("{:?}", f)).join(",")), + Self::Flags => Some(Flags::matching(data).map(|f| format!("{f:?}")).join(",")), Self::CompleteListOf16BitServiceClassUuids | Self::IncompleteListOf16BitServiceClassUuids | Self::ListOf16BitServiceSolicitationUuids => { @@ -174,8 +174,8 @@ impl CommonDataType { .map(|uuid| { SERVICE_IDS .get(&uuid) - .map(|name| format!("{:?} ({name})", uuid)) - .unwrap_or_else(|| format!("{:?}", uuid)) + .map(|name| format!("{uuid:?} ({name})")) + .unwrap_or_else(|| format!("{uuid:?}")) }) .join(", ") }) @@ -185,14 +185,14 @@ impl CommonDataType { | Self::IncompleteListOf32BitServiceClassUuids | Self::ListOf32BitServiceSolicitationUuids => { combinator::complete(multi::many0(Uuid32::parse))(data) - .map(|(_res, uuids)| uuids.into_iter().map(|u| format!("{:?}", u)).join(", ")) + .map(|(_res, uuids)| uuids.into_iter().map(|u| format!("{u:?}")).join(", ")) .ok() } Self::CompleteListOf128BitServiceClassUuids | Self::IncompleteListOf128BitServiceClassUuids | Self::ListOf128BitServiceSolicitationUuids => { combinator::complete(multi::many0(Uuid128::parse_le))(data) - .map(|(_res, uuids)| uuids.into_iter().map(|u| format!("{:?}", u)).join(", ")) + .map(|(_res, uuids)| uuids.into_iter().map(|u| format!("{u:?}")).join(", ")) .ok() } Self::ServiceData16BitUuid => Uuid16::parse_le(data) @@ -201,8 +201,8 @@ impl CommonDataType { "service={:?}, data={}", SERVICE_IDS .get(&uuid) - .map(|name| format!("{:?} ({name})", uuid)) - .unwrap_or_else(|| format!("{:?}", uuid)), + .map(|name| format!("{uuid:?} ({name})")) + .unwrap_or_else(|| format!("{uuid:?}")), hex::encode_upper(rem) ) }) @@ -214,7 +214,7 @@ impl CommonDataType { .map(|(rem, uuid)| format!("service={:?}, data={}", uuid, hex::encode_upper(rem))) .ok(), Self::ShortenedLocalName | Self::CompleteLocalName => { - std::str::from_utf8(data).ok().map(|s| format!("\"{}\"", s)) + std::str::from_utf8(data).ok().map(|s| format!("\"{s}\"")) } Self::TxPowerLevel => { let (_, tx) = @@ -230,7 +230,7 @@ impl CommonDataType { COMPANY_IDS .get(&id) .map(|s| s.to_string()) - .unwrap_or_else(|| format!("{:?}", id)), + .unwrap_or_else(|| format!("{id:?}")), hex::encode_upper(rem) )) } diff --git a/rust/src/cli/l2cap/client_bridge.rs b/rust/src/cli/l2cap/client_bridge.rs index 31bc021..7412864 100644 --- a/rust/src/cli/l2cap/client_bridge.rs +++ b/rust/src/cli/l2cap/client_bridge.rs @@ -56,7 +56,7 @@ pub async fn start(args: &Args, device: &mut Device) -> PyResult<()> { ble_connection.on_disconnection(|_py, reason| { let disconnection_info = match HciConstant::error_name(reason) { Ok(info_string) => info_string, - Err(py_err) => format!("failed to get disconnection error name ({})", py_err), + Err(py_err) => format!("failed to get disconnection error name ({py_err})"), }; println!( "{} {}", @@ -114,10 +114,10 @@ async fn proxy_data_between_tcp_and_l2cap( mtu: Option, mps: Option, ) -> PyResult<()> { - println!("{}", format!("<<< TCP connection from {}", addr).magenta()); + println!("{}", format!("<<< TCP connection from {addr}").magenta()); println!( "{}", - format!(">>> Opening L2CAP channel on PSM = {}", psm).yellow() + format!(">>> Opening L2CAP channel on PSM = {psm}").yellow() ); let mut l2cap_channel = match ble_connection diff --git a/rust/src/cli/l2cap/mod.rs b/rust/src/cli/l2cap/mod.rs index 3f86b24..5cdc897 100644 --- a/rust/src/cli/l2cap/mod.rs +++ b/rust/src/cli/l2cap/mod.rs @@ -158,7 +158,7 @@ async fn proxy_tcp_rx_to_l2cap_tx( } } Err(e) => { - println!("{}", format!("!!! TCP connection lost: {}", e).red()); + println!("{}", format!("!!! TCP connection lost: {e}").red()); if let Some(mut channel) = l2cap_channel.lock().await.take() { let _ = channel.disconnect().await.map_err(|e| { eprintln!("Failed to call disconnect on l2cap channel: {e}"); diff --git a/rust/src/cli/l2cap/server_bridge.rs b/rust/src/cli/l2cap/server_bridge.rs index 3f8041a..f993c01 100644 --- a/rust/src/cli/l2cap/server_bridge.rs +++ b/rust/src/cli/l2cap/server_bridge.rs @@ -83,7 +83,7 @@ pub async fn start(args: &Args, device: &mut Device) -> PyResult<()> { connection.on_disconnection(|_py, reason| { let disconnection_info = match HciConstant::error_name(reason) { Ok(info_string) => info_string, - Err(py_err) => format!("failed to get disconnection error name ({})", py_err), + Err(py_err) => format!("failed to get disconnection error name ({py_err})"), }; println!( "{} {}", diff --git a/rust/src/cli/usb/mod.rs b/rust/src/cli/usb/mod.rs index 5cab29a..32de4e0 100644 --- a/rust/src/cli/usb/mod.rs +++ b/rust/src/cli/usb/mod.rs @@ -100,7 +100,7 @@ pub(crate) fn probe(verbose: bool) -> anyhow::Result<()> { .map(|serials| serials.contains(s)) .unwrap_or(false) { - transport_names.push(format!("{}/{}", basic_transport_name, s)) + transport_names.push(format!("{basic_transport_name}/{s}")) } } @@ -310,7 +310,7 @@ impl ClassInfo { self.sub_class, self.protocol, self.protocol_name() - .map(|s| format!(" [{}]", s)) + .map(|s| format!(" [{s}]")) .unwrap_or_default() ) }