Fix Rust linter errors

This commit is contained in:
Josh Wu
2025-07-02 12:32:41 +08:00
parent 88777710a4
commit 3cb97d2373
6 changed files with 18 additions and 18 deletions

View File

@@ -127,7 +127,7 @@ async fn main() -> PyResult<()> {
} else { } else {
matching matching
.iter() .iter()
.map(|t| format!("{}", t)) .map(|t| format!("{t}"))
.join(" / ") .join(" / ")
.blue() .blue()
.to_string() .to_string()
@@ -148,7 +148,7 @@ async fn main() -> PyResult<()> {
.next() .next()
.unwrap_or_else(|| format!("0x{}", hex::encode_upper(&data))); .unwrap_or_else(|| format!("0x{}", hex::encode_upper(&data)));
println!(" [{}]: {}", code_str, data_str) println!(" [{code_str}]: {data_str}")
}); });
Ok(()) Ok(())

View File

@@ -163,7 +163,7 @@ impl CommonDataType {
/// Apply type-specific human-oriented formatting to data, if any is applicable /// Apply type-specific human-oriented formatting to data, if any is applicable
pub fn format_data(&self, data: &[u8]) -> Option<String> { pub fn format_data(&self, data: &[u8]) -> Option<String> {
match self { 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::CompleteListOf16BitServiceClassUuids
| Self::IncompleteListOf16BitServiceClassUuids | Self::IncompleteListOf16BitServiceClassUuids
| Self::ListOf16BitServiceSolicitationUuids => { | Self::ListOf16BitServiceSolicitationUuids => {
@@ -174,8 +174,8 @@ impl CommonDataType {
.map(|uuid| { .map(|uuid| {
SERVICE_IDS SERVICE_IDS
.get(&uuid) .get(&uuid)
.map(|name| format!("{:?} ({name})", uuid)) .map(|name| format!("{uuid:?} ({name})"))
.unwrap_or_else(|| format!("{:?}", uuid)) .unwrap_or_else(|| format!("{uuid:?}"))
}) })
.join(", ") .join(", ")
}) })
@@ -185,14 +185,14 @@ impl CommonDataType {
| Self::IncompleteListOf32BitServiceClassUuids | Self::IncompleteListOf32BitServiceClassUuids
| Self::ListOf32BitServiceSolicitationUuids => { | Self::ListOf32BitServiceSolicitationUuids => {
combinator::complete(multi::many0(Uuid32::parse))(data) 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() .ok()
} }
Self::CompleteListOf128BitServiceClassUuids Self::CompleteListOf128BitServiceClassUuids
| Self::IncompleteListOf128BitServiceClassUuids | Self::IncompleteListOf128BitServiceClassUuids
| Self::ListOf128BitServiceSolicitationUuids => { | Self::ListOf128BitServiceSolicitationUuids => {
combinator::complete(multi::many0(Uuid128::parse_le))(data) 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() .ok()
} }
Self::ServiceData16BitUuid => Uuid16::parse_le(data) Self::ServiceData16BitUuid => Uuid16::parse_le(data)
@@ -201,8 +201,8 @@ impl CommonDataType {
"service={:?}, data={}", "service={:?}, data={}",
SERVICE_IDS SERVICE_IDS
.get(&uuid) .get(&uuid)
.map(|name| format!("{:?} ({name})", uuid)) .map(|name| format!("{uuid:?} ({name})"))
.unwrap_or_else(|| format!("{:?}", uuid)), .unwrap_or_else(|| format!("{uuid:?}")),
hex::encode_upper(rem) hex::encode_upper(rem)
) )
}) })
@@ -214,7 +214,7 @@ impl CommonDataType {
.map(|(rem, uuid)| format!("service={:?}, data={}", uuid, hex::encode_upper(rem))) .map(|(rem, uuid)| format!("service={:?}, data={}", uuid, hex::encode_upper(rem)))
.ok(), .ok(),
Self::ShortenedLocalName | Self::CompleteLocalName => { 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 => { Self::TxPowerLevel => {
let (_, tx) = let (_, tx) =
@@ -230,7 +230,7 @@ impl CommonDataType {
COMPANY_IDS COMPANY_IDS
.get(&id) .get(&id)
.map(|s| s.to_string()) .map(|s| s.to_string())
.unwrap_or_else(|| format!("{:?}", id)), .unwrap_or_else(|| format!("{id:?}")),
hex::encode_upper(rem) hex::encode_upper(rem)
)) ))
} }

View File

@@ -56,7 +56,7 @@ pub async fn start(args: &Args, device: &mut Device) -> PyResult<()> {
ble_connection.on_disconnection(|_py, reason| { ble_connection.on_disconnection(|_py, reason| {
let disconnection_info = match HciConstant::error_name(reason) { let disconnection_info = match HciConstant::error_name(reason) {
Ok(info_string) => info_string, 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!( println!(
"{} {}", "{} {}",
@@ -114,10 +114,10 @@ async fn proxy_data_between_tcp_and_l2cap(
mtu: Option<u16>, mtu: Option<u16>,
mps: Option<u16>, mps: Option<u16>,
) -> PyResult<()> { ) -> PyResult<()> {
println!("{}", format!("<<< TCP connection from {}", addr).magenta()); println!("{}", format!("<<< TCP connection from {addr}").magenta());
println!( println!(
"{}", "{}",
format!(">>> Opening L2CAP channel on PSM = {}", psm).yellow() format!(">>> Opening L2CAP channel on PSM = {psm}").yellow()
); );
let mut l2cap_channel = match ble_connection let mut l2cap_channel = match ble_connection

View File

@@ -158,7 +158,7 @@ async fn proxy_tcp_rx_to_l2cap_tx(
} }
} }
Err(e) => { 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() { if let Some(mut channel) = l2cap_channel.lock().await.take() {
let _ = channel.disconnect().await.map_err(|e| { let _ = channel.disconnect().await.map_err(|e| {
eprintln!("Failed to call disconnect on l2cap channel: {e}"); eprintln!("Failed to call disconnect on l2cap channel: {e}");

View File

@@ -83,7 +83,7 @@ pub async fn start(args: &Args, device: &mut Device) -> PyResult<()> {
connection.on_disconnection(|_py, reason| { connection.on_disconnection(|_py, reason| {
let disconnection_info = match HciConstant::error_name(reason) { let disconnection_info = match HciConstant::error_name(reason) {
Ok(info_string) => info_string, 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!( println!(
"{} {}", "{} {}",

View File

@@ -100,7 +100,7 @@ pub(crate) fn probe(verbose: bool) -> anyhow::Result<()> {
.map(|serials| serials.contains(s)) .map(|serials| serials.contains(s))
.unwrap_or(false) .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.sub_class,
self.protocol, self.protocol,
self.protocol_name() self.protocol_name()
.map(|s| format!(" [{}]", s)) .map(|s| format!(" [{s}]"))
.unwrap_or_default() .unwrap_or_default()
) )
} }