From 989ba34a205fcc6ab60155112ba98fb4da74c932 Mon Sep 17 00:00:00 2001 From: Corentin LIAUD Date: Tue, 23 Dec 2025 21:14:21 +0100 Subject: [PATCH] chore: clippy lints + v2.1.19 --- Cargo.toml | 2 +- adb_client/README.md | 2 +- adb_client/src/device/adb_tcp_device.rs | 8 ++++---- adb_client/src/device/adb_usb_device.rs | 14 +++++++------- adb_client/src/device/commands/list.rs | 2 +- adb_client/src/emulator_device/commands/rotate.rs | 2 +- adb_client/src/emulator_device/commands/sms.rs | 2 +- adb_client/src/server/models/adb_version.rs | 1 + adb_client/src/server_device/commands/list.rs | 4 ++-- adb_client/src/server_device/commands/recv.rs | 2 +- adb_client/src/server_device/commands/send.rs | 2 +- adb_client/src/server_device/commands/stat.rs | 2 +- .../src/transports/tcp_emulator_transport.rs | 5 +++-- adb_client/src/transports/tcp_server_transport.rs | 4 +++- pyadb_client/src/adb_usb_device.rs | 2 ++ 15 files changed, 30 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dc3cf22..2c44a8f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://github.com/cocool97/adb_client" keywords = ["adb", "android", "tcp", "usb"] license = "MIT" repository = "https://github.com/cocool97/adb_client" -version = "2.1.18" +version = "2.1.19" rust-version = "1.91.0" # To build locally when working on a new release diff --git a/adb_client/README.md b/adb_client/README.md index bc8af35..81f10e9 100644 --- a/adb_client/README.md +++ b/adb_client/README.md @@ -1,4 +1,4 @@ -# adb_client +# `adb_client` [![MIT licensed](https://img.shields.io/crates/l/adb_client.svg)](./LICENSE-MIT) [![Documentation](https://docs.rs/adb_client/badge.svg)](https://docs.rs/adb_client) diff --git a/adb_client/src/device/adb_tcp_device.rs b/adb_client/src/device/adb_tcp_device.rs index 17ea6f1..61821ae 100644 --- a/adb_client/src/device/adb_tcp_device.rs +++ b/adb_client/src/device/adb_tcp_device.rs @@ -1,5 +1,5 @@ use std::io::Write; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::{io::Read, net::SocketAddr}; use super::adb_message_device::ADBMessageDevice; @@ -22,16 +22,16 @@ impl ADBTcpDevice { } /// Instantiate a new [`ADBTcpDevice`] using a custom private key path - pub fn new_with_custom_private_key( + pub fn new_with_custom_private_key>( address: SocketAddr, - private_key_path: PathBuf, + private_key_path: P, ) -> Result { let private_key = if let Some(private_key) = read_adb_private_key(&private_key_path)? { private_key } else { log::warn!( "No private key found at path {}. Using a temporary random one.", - private_key_path.display() + private_key_path.as_ref().display() ); ADBRsaKey::new_random()? }; diff --git a/adb_client/src/device/adb_usb_device.rs b/adb_client/src/device/adb_usb_device.rs index 0f0694a..71b4d4d 100644 --- a/adb_client/src/device/adb_usb_device.rs +++ b/adb_client/src/device/adb_usb_device.rs @@ -110,12 +110,12 @@ impl ADBUSBDevice { } /// Instantiate a new [`ADBUSBDevice`] using a custom private key path - pub fn new_with_custom_private_key( + pub fn new_with_custom_private_key>( vendor_id: u16, product_id: u16, - private_key_path: PathBuf, + private_key_path: P, ) -> Result { - Self::new_from_transport_inner(USBTransport::new(vendor_id, product_id)?, &private_key_path) + Self::new_from_transport_inner(USBTransport::new(vendor_id, product_id)?, private_key_path) } /// Instantiate a new [`ADBUSBDevice`] from a [`USBTransport`] and an optional private key path. @@ -131,16 +131,16 @@ impl ADBUSBDevice { Self::new_from_transport_inner(transport, &private_key_path) } - fn new_from_transport_inner( + fn new_from_transport_inner>( transport: USBTransport, - private_key_path: &PathBuf, + private_key_path: P, ) -> Result { - let private_key = if let Some(private_key) = read_adb_private_key(private_key_path)? { + let private_key = if let Some(private_key) = read_adb_private_key(&private_key_path)? { private_key } else { log::warn!( "No private key found at path {}. Using a temporary random one.", - private_key_path.display() + private_key_path.as_ref().display() ); ADBRsaKey::new_random()? }; diff --git a/adb_client/src/device/commands/list.rs b/adb_client/src/device/commands/list.rs index c0e4f12..5a876e1 100644 --- a/adb_client/src/device/commands/list.rs +++ b/adb_client/src/device/commands/list.rs @@ -147,7 +147,7 @@ impl ADBMessageDevice { let name = String::from_utf8(name_buf)?; // First 9 bits are the file permissions - let permissions = mode & 0b111111111; + let permissions = mode & 0b1_1111_1111; // Bits 14 to 16 are the file type let item_type = match (mode >> 13) & 0b111 { 0b010 => ADBListItemType::Directory, diff --git a/adb_client/src/emulator_device/commands/rotate.rs b/adb_client/src/emulator_device/commands/rotate.rs index 0da9d3e..eef3195 100644 --- a/adb_client/src/emulator_device/commands/rotate.rs +++ b/adb_client/src/emulator_device/commands/rotate.rs @@ -3,6 +3,6 @@ use crate::{ADBEmulatorDevice, Result, emulator_device::ADBEmulatorCommand}; impl ADBEmulatorDevice { /// Send a SMS to this emulator with given content with given phone number pub fn rotate(&mut self) -> Result<()> { - self.connect()?.send_command(ADBEmulatorCommand::Rotate) + self.connect()?.send_command(&ADBEmulatorCommand::Rotate) } } diff --git a/adb_client/src/emulator_device/commands/sms.rs b/adb_client/src/emulator_device/commands/sms.rs index 627feb9..b7caa32 100644 --- a/adb_client/src/emulator_device/commands/sms.rs +++ b/adb_client/src/emulator_device/commands/sms.rs @@ -3,7 +3,7 @@ use crate::{ADBEmulatorDevice, Result, emulator_device::ADBEmulatorCommand}; impl ADBEmulatorDevice { /// Send a SMS to this emulator with given content with given phone number pub fn send_sms(&mut self, phone_number: &str, content: &str) -> Result<()> { - self.connect()?.send_command(ADBEmulatorCommand::Sms( + self.connect()?.send_command(&ADBEmulatorCommand::Sms( phone_number.to_string(), content.to_string(), )) diff --git a/adb_client/src/server/models/adb_version.rs b/adb_client/src/server/models/adb_version.rs index def13c4..f7eebe5 100644 --- a/adb_client/src/server/models/adb_version.rs +++ b/adb_client/src/server/models/adb_version.rs @@ -16,6 +16,7 @@ pub struct AdbVersion { impl AdbVersion { /// Instantiates a new [`AdbVersion`]. + #[must_use] pub fn new(minor: u32, revision: u32) -> Self { Self { major: 1, diff --git a/adb_client/src/server_device/commands/list.rs b/adb_client/src/server_device/commands/list.rs index 96d6a07..51a46a5 100644 --- a/adb_client/src/server_device/commands/list.rs +++ b/adb_client/src/server_device/commands/list.rs @@ -18,7 +18,7 @@ impl ADBServerDevice { self.transport.send_adb_request(AdbServerCommand::Sync)?; // Send a list command - self.transport.send_sync_request(SyncCommand::List)?; + self.transport.send_sync_request(&SyncCommand::List)?; self.handle_list_command(path) } @@ -58,7 +58,7 @@ impl ADBServerDevice { let name = String::from_utf8(name_buf)?; // First 9 bits are the file permissions - let permissions = mode & 0b111111111; + let permissions = mode & 0b1_1111_1111; // Bits 14 to 16 are the file type let item_type = match (mode >> 13) & 0b111 { 0b010 => ADBListItemType::Directory, diff --git a/adb_client/src/server_device/commands/recv.rs b/adb_client/src/server_device/commands/recv.rs index ae4b9dd..f452853 100644 --- a/adb_client/src/server_device/commands/recv.rs +++ b/adb_client/src/server_device/commands/recv.rs @@ -72,7 +72,7 @@ impl ADBServerDevice { self.transport.send_adb_request(AdbServerCommand::Sync)?; // Send a recv command - self.transport.send_sync_request(SyncCommand::Recv)?; + self.transport.send_sync_request(&SyncCommand::Recv)?; self.handle_recv_command(path, stream) } diff --git a/adb_client/src/server_device/commands/send.rs b/adb_client/src/server_device/commands/send.rs index 9cf8b57..f06f17d 100644 --- a/adb_client/src/server_device/commands/send.rs +++ b/adb_client/src/server_device/commands/send.rs @@ -50,7 +50,7 @@ impl ADBServerDevice { self.transport.send_adb_request(AdbServerCommand::Sync)?; // Send a send command - self.transport.send_sync_request(SyncCommand::Send)?; + self.transport.send_sync_request(&SyncCommand::Send)?; self.handle_send_command(stream, path) } diff --git a/adb_client/src/server_device/commands/stat.rs b/adb_client/src/server_device/commands/stat.rs index 3d4f428..fd0d5ee 100644 --- a/adb_client/src/server_device/commands/stat.rs +++ b/adb_client/src/server_device/commands/stat.rs @@ -44,7 +44,7 @@ impl ADBServerDevice { self.transport.send_adb_request(AdbServerCommand::Sync)?; // Send a "Stat" command - self.transport.send_sync_request(SyncCommand::Stat)?; + self.transport.send_sync_request(&SyncCommand::Stat)?; self.handle_stat_command(path) } diff --git a/adb_client/src/transports/tcp_emulator_transport.rs b/adb_client/src/transports/tcp_emulator_transport.rs index b93c4cc..ae6d390 100644 --- a/adb_client/src/transports/tcp_emulator_transport.rs +++ b/adb_client/src/transports/tcp_emulator_transport.rs @@ -16,6 +16,7 @@ pub struct TCPEmulatorTransport { impl TCPEmulatorTransport { /// Instantiates a new instance of [`TCPEmulatorTransport`] + #[must_use] pub fn new(socket_addr: SocketAddrV4) -> Self { Self { socket_addr, @@ -48,11 +49,11 @@ impl TCPEmulatorTransport { /// Send an authenticate request to this emulator pub fn authenticate(&mut self) -> Result<()> { let token = self.get_authentication_token()?; - self.send_command(ADBEmulatorCommand::Authenticate(token)) + self.send_command(&ADBEmulatorCommand::Authenticate(token)) } /// Send an [`ADBEmulatorCommand`] to this emulator - pub(crate) fn send_command(&mut self, command: ADBEmulatorCommand) -> Result<()> { + pub(crate) fn send_command(&mut self, command: &ADBEmulatorCommand) -> Result<()> { let mut connection = self.get_raw_connection()?; // Send command diff --git a/adb_client/src/transports/tcp_server_transport.rs b/adb_client/src/transports/tcp_server_transport.rs index 20cac72..e2052f2 100644 --- a/adb_client/src/transports/tcp_server_transport.rs +++ b/adb_client/src/transports/tcp_server_transport.rs @@ -34,6 +34,7 @@ impl TCPServerTransport { } /// Instantiate a new instance of [`TCPServerTransport`] using given address, or default if not specified. + #[must_use] pub fn new_or_default(socket_addr: Option) -> Self { match socket_addr { Some(s) => Self::new(s), @@ -42,6 +43,7 @@ impl TCPServerTransport { } /// Get underlying [`SocketAddrV4`] + #[must_use] pub fn get_socketaddr(&self) -> SocketAddrV4 { self.socket_addr } @@ -90,7 +92,7 @@ impl TCPServerTransport { } /// Send the given [`SyncCommand`] to ADB server, and checks that the request has been taken in consideration. - pub(crate) fn send_sync_request(&mut self, command: SyncCommand) -> Result<()> { + pub(crate) fn send_sync_request(&mut self, command: &SyncCommand) -> Result<()> { // First 4 bytes are the name of the command we want to send // (e.g. "SEND", "RECV", "STAT", "LIST") Ok(self diff --git a/pyadb_client/src/adb_usb_device.rs b/pyadb_client/src/adb_usb_device.rs index ea3cf5e..b2707ce 100644 --- a/pyadb_client/src/adb_usb_device.rs +++ b/pyadb_client/src/adb_usb_device.rs @@ -21,6 +21,7 @@ impl PyADBUSBDevice { } /// Run shell commands on device and return the output (stdout + stderr merged) + #[expect(clippy::needless_pass_by_value)] pub fn shell_command(&mut self, commands: Vec) -> Result> { let mut output = Vec::new(); let commands: Vec<&str> = commands.iter().map(|x| &**x).collect(); @@ -41,6 +42,7 @@ impl PyADBUSBDevice { } /// Install a package installed on the device + #[expect(clippy::needless_pass_by_value)] pub fn install(&mut self, apk_path: PathBuf) -> Result<()> { Ok(self.0.install(&apk_path)?) }