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 {
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(())

View File

@@ -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<String> {
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)
))
}

View File

@@ -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<u16>,
mps: Option<u16>,
) -> 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

View File

@@ -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}");

View File

@@ -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!(
"{} {}",

View File

@@ -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()
)
}