From e0b6bb01397cf57ac8109a58d789b1daf96270ac Mon Sep 17 00:00:00 2001 From: Corentin LIAUD Date: Sun, 19 Oct 2025 14:58:35 +0200 Subject: [PATCH] chore: cargo clippy -- -W clippy::pedantic --- adb_cli/Cargo.toml | 10 +++---- adb_cli/src/adb_termios.rs | 4 +-- adb_cli/src/handlers/host_commands.rs | 13 ++++---- adb_cli/src/handlers/local_commands.rs | 2 +- adb_cli/src/main.rs | 8 ++--- adb_cli/src/models/device.rs | 2 +- adb_cli/src/utils.rs | 5 +--- adb_client/Cargo.toml | 30 +++++++++---------- adb_client/src/adb_device_ext.rs | 2 +- adb_client/src/device/adb_message_device.rs | 12 ++++---- .../src/device/adb_message_device_commands.rs | 2 +- adb_client/src/device/adb_tcp_device.rs | 6 ++-- .../src/device/adb_transport_message.rs | 4 +-- adb_client/src/device/adb_usb_device.rs | 29 +++++++++--------- adb_client/src/device/commands/framebuffer.rs | 4 +-- adb_client/src/device/commands/pull.rs | 2 +- adb_client/src/device/commands/push.rs | 2 +- adb_client/src/device/commands/shell.rs | 4 +-- adb_client/src/device/models/adb_rsa_key.rs | 10 ++++--- .../src/device/models/message_commands.rs | 30 +++++++++---------- .../emulator_device/adb_emulator_device.rs | 6 ++-- .../models/adb_emulator_command.rs | 3 +- adb_client/src/error.rs | 3 ++ adb_client/src/mdns/mdns_discovery.rs | 1 - adb_client/src/server/adb_server.rs | 10 +++---- adb_client/src/server/commands/devices.rs | 6 ++-- adb_client/src/server/models/adb_version.rs | 2 +- adb_client/src/server/models/device_long.rs | 16 +++++----- adb_client/src/server/models/server_status.rs | 6 ++-- .../src/server_device/adb_server_device.rs | 6 ++-- .../adb_server_device_commands.rs | 10 +++---- adb_client/src/server_device/commands/list.rs | 2 +- adb_client/src/server_device/commands/recv.rs | 4 +-- adb_client/src/server_device/commands/send.rs | 11 +++---- adb_client/src/server_device/commands/stat.rs | 2 +- .../src/transports/tcp_emulator_transport.rs | 18 +++++------ .../src/transports/tcp_server_transport.rs | 16 +++++----- adb_client/src/transports/tcp_transport.rs | 16 ++++------ adb_client/src/transports/usb_transport.rs | 19 +++++------- pyadb_client/Cargo.toml | 4 +-- pyadb_client/src/adb_server.rs | 9 ++++-- 41 files changed, 175 insertions(+), 176 deletions(-) diff --git a/adb_cli/Cargo.toml b/adb_cli/Cargo.toml index 2885bc9..291062b 100644 --- a/adb_cli/Cargo.toml +++ b/adb_cli/Cargo.toml @@ -11,11 +11,11 @@ rust-version.workspace = true version.workspace = true [dependencies] -adb_client = { version = "^2.0.0" } -anyhow = { version = "1.0.94" } -clap = { version = "4.5.23", features = ["derive"] } -env_logger = { version = "0.11.5" } -log = { version = "0.4.26" } +adb_client = { version = "^2.1.17" } +anyhow = { version = "1.0.100" } +clap = { version = "4.5.49", features = ["derive"] } +env_logger = { version = "0.11.8" } +log = { version = "0.4.28" } [target.'cfg(unix)'.dependencies] termios = { version = "0.3.3" } diff --git a/adb_cli/src/adb_termios.rs b/adb_cli/src/adb_termios.rs index be45a1e..2445c37 100644 --- a/adb_cli/src/adb_termios.rs +++ b/adb_cli/src/adb_termios.rs @@ -13,7 +13,7 @@ pub struct ADBTermios { } impl ADBTermios { - pub fn new(fd: impl AsRawFd) -> Result { + pub fn new(fd: &impl AsRawFd) -> Result { let mut new_termios = Termios::from_fd(fd.as_raw_fd())?; let old_termios = new_termios; // Saves previous state new_termios.c_lflag = 0; @@ -36,7 +36,7 @@ impl Drop for ADBTermios { fn drop(&mut self) { // Custom drop implementation, restores previous termios structure. if let Err(e) = tcsetattr(self.fd, TCSANOW, &self.old_termios) { - log::error!("Error while dropping ADBTermios: {e}") + log::error!("Error while dropping ADBTermios: {e}"); } } } diff --git a/adb_cli/src/handlers/host_commands.rs b/adb_cli/src/handlers/host_commands.rs index 250f465..5a7c7ee 100644 --- a/adb_cli/src/handlers/host_commands.rs +++ b/adb_cli/src/handlers/host_commands.rs @@ -53,12 +53,15 @@ pub fn handle_host_commands(server_command: ServerCommand) -> Resul let server_status = adb_server.server_status()?; match server_status.mdns_backend { MDNSBackend::Unknown => log::info!("unknown mdns backend..."), - MDNSBackend::Bonjour => match check { - true => log::info!("mdns daemon version [Bonjour]"), - false => log::info!("ERROR: mdns daemon unavailable"), - }, + MDNSBackend::Bonjour => { + if check { + log::info!("mdns daemon version [Bonjour]"); + } else { + log::info!("ERROR: mdns daemon unavailable"); + } + } MDNSBackend::OpenScreen => { - log::info!("mdns daemon version [Openscreen discovery 0.0.0]") + log::info!("mdns daemon version [Openscreen discovery 0.0.0]"); } } } diff --git a/adb_cli/src/handlers/local_commands.rs b/adb_cli/src/handlers/local_commands.rs index 92411ad..101310d 100644 --- a/adb_cli/src/handlers/local_commands.rs +++ b/adb_cli/src/handlers/local_commands.rs @@ -14,7 +14,7 @@ pub fn handle_local_commands( let features = device .host_features()? .iter() - .map(|v| v.to_string()) + .map(ToString::to_string) .reduce(|a, b| format!("{a},{b}")) .ok_or(anyhow!("cannot list features"))?; log::info!("Available host features: {features}"); diff --git a/adb_cli/src/main.rs b/adb_cli/src/main.rs index 3ac5af6..c99e683 100644 --- a/adb_cli/src/main.rs +++ b/adb_cli/src/main.rs @@ -94,7 +94,7 @@ fn main() -> Result<()> { "Found device {} with addresses {:?}", device.fullname, device.addresses - ) + ); } return Ok(service.shutdown()?); @@ -108,7 +108,7 @@ fn main() -> Result<()> { // Using a scope here would call drop() too early.. #[cfg(any(target_os = "linux", target_os = "macos"))] { - let mut adb_termios = ADBTermios::new(std::io::stdin())?; + let mut adb_termios = ADBTermios::new(&std::io::stdin())?; adb_termios.set_adb_termios()?; device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?; } @@ -118,7 +118,7 @@ fn main() -> Result<()> { device.shell(&mut std::io::stdin(), Box::new(std::io::stdout()))?; } } else { - let commands: Vec<&str> = commands.iter().map(|v| v.as_str()).collect(); + let commands: Vec<&str> = commands.iter().map(String::as_str).collect(); device.shell_command(&commands, &mut std::io::stdout())?; } } @@ -136,7 +136,7 @@ fn main() -> Result<()> { } DeviceCommands::Reboot { reboot_type } => { log::info!("Reboots device in mode {reboot_type:?}"); - device.reboot(reboot_type.into())? + device.reboot(reboot_type.into())?; } DeviceCommands::Push { filename, path } => { let mut input = File::open(Path::new(&filename))?; diff --git a/adb_cli/src/models/device.rs b/adb_cli/src/models/device.rs index bcaa9ce..8e7eefb 100644 --- a/adb_cli/src/models/device.rs +++ b/adb_cli/src/models/device.rs @@ -19,7 +19,7 @@ pub enum DeviceCommands { /// The package whose activity is to be invoked #[clap(short = 'p', long = "package")] package: String, - /// The activity to be invoked itself, Usually it is MainActivity + /// The activity to be invoked itself, Usually it is `MainActivity` #[clap(short = 'a', long = "activity")] activity: String, }, diff --git a/adb_cli/src/utils.rs b/adb_cli/src/utils.rs index b5b01db..c471d5a 100644 --- a/adb_cli/src/utils.rs +++ b/adb_cli/src/utils.rs @@ -5,10 +5,7 @@ pub unsafe fn setup_logger(debug: bool) { // RUST_LOG variable has more priority then "--debug" flag if std::env::var("RUST_LOG").is_err() { - let level = match debug { - true => "trace", - false => "info", - }; + let level = if debug { "trace" } else { "info" }; unsafe { std::env::set_var("RUST_LOG", level) }; } diff --git a/adb_client/Cargo.toml b/adb_client/Cargo.toml index 590f75a..865152c 100644 --- a/adb_client/Cargo.toml +++ b/adb_client/Cargo.toml @@ -14,33 +14,33 @@ version.workspace = true base64 = { version = "0.22.1" } bincode = { version = "1.3.3" } byteorder = { version = "1.5.0" } -chrono = { version = "0.4.40", default-features = false, features = ["std"] } -homedir = { version = "= 0.3.4" } -image = { version = "0.25.5", default-features = false } -log = { version = "0.4.26" } -mdns-sd = { version = "0.13.9", default-features = false, features = [ +chrono = { version = "0.4.42", default-features = false, features = ["std"] } +homedir = { version = "=0.3.4" } +image = { version = "0.25.8", default-features = false } +log = { version = "0.4.28" } +mdns-sd = { version = "0.13.11", default-features = false, features = [ "logging", ] } num-bigint = { version = "0.8.4", package = "num-bigint-dig" } num-traits = { version = "0.2.19" } quick-protobuf = { version = "0.8.1" } -rand = { version = "0.9.0" } -rcgen = { version = "0.13.1", default-features = false, features = [ +rand = { version = "0.9.2" } +rcgen = { version = "0.13.2", default-features = false, features = [ "aws_lc_rs", "pem", ] } -regex = { version = "1.11.1", features = ["perf", "std", "unicode"] } -rsa = { version = "0.9.7" } +regex = { version = "1.12.2", features = ["perf", "std", "unicode"] } +rsa = { version = "0.9.8" } rusb = { version = "0.9.4", features = ["vendored"] } -rustls = { version = "0.23.27" } -rustls-pki-types = { version = "1.11.0" } -serde = { version = "1.0.216", features = ["derive"] } -serde_repr = { version = "0.1.19" } +rustls = { version = "0.23.33" } +rustls-pki-types = { version = "1.12.0" } +serde = { version = "1.0.228", features = ["derive"] } +serde_repr = { version = "0.1.20" } sha1 = { version = "0.10.6", features = ["oid"] } -thiserror = { version = "2.0.7" } +thiserror = { version = "2.0.17" } [dev-dependencies] -anyhow = { version = "1.0.93" } +anyhow = { version = "1.0.100" } criterion = { version = "0.6.0" } # Used for benchmarks [[bench]] diff --git a/adb_client/src/adb_device_ext.rs b/adb_client/src/adb_device_ext.rs index 9fc99a4..a342f3a 100644 --- a/adb_client/src/adb_device_ext.rs +++ b/adb_client/src/adb_device_ext.rs @@ -13,7 +13,7 @@ pub trait ADBDeviceExt { /// Starts an interactive shell session on the device. /// Input data is read from reader and write to writer. - fn shell(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()>; + fn shell(&mut self, reader: &mut dyn Read, writer: Box) -> Result<()>; /// Display the stat information for a remote file fn stat(&mut self, remote_path: &str) -> Result; diff --git a/adb_client/src/device/adb_message_device.rs b/adb_client/src/device/adb_message_device.rs index e3036c9..6964f8c 100644 --- a/adb_client/src/device/adb_message_device.rs +++ b/adb_client/src/device/adb_message_device.rs @@ -70,7 +70,7 @@ impl ADBMessageDevice { match len.take() { Some(0) | None => { rdr.seek_relative(4)?; - len.replace(rdr.read_u32::()? as u64); + len.replace(u64::from(rdr.read_u32::()?)); } Some(length) => { let remaining_bytes = payload.len() as u64 - rdr.position(); @@ -101,9 +101,9 @@ impl ADBMessageDevice { remote_id: u32, mut reader: R, ) -> std::result::Result<(), RustADBError> { - let mut buffer = [0; BUFFER_SIZE]; + let mut buffer = vec![0; BUFFER_SIZE].into_boxed_slice(); let amount_read = reader.read(&mut buffer)?; - let subcommand_data = MessageSubcommand::Data.with_arg(amount_read as u32); + let subcommand_data = MessageSubcommand::Data.with_arg(u32::try_from(amount_read)?); let mut serialized_message = bincode::serialize(&subcommand_data).map_err(|_e| RustADBError::ConversionError)?; @@ -119,7 +119,7 @@ impl ADBMessageDevice { self.send_and_expect_okay(message)?; loop { - let mut buffer = [0; BUFFER_SIZE]; + let mut buffer = vec![0; BUFFER_SIZE].into_boxed_slice(); match reader.read(&mut buffer) { Ok(0) => { @@ -150,7 +150,7 @@ impl ADBMessageDevice { } } Ok(size) => { - let subcommand_data = MessageSubcommand::Data.with_arg(size as u32); + let subcommand_data = MessageSubcommand::Data.with_arg(u32::try_from(size)?); let mut serialized_message = bincode::serialize(&subcommand_data) .map_err(|_e| RustADBError::ConversionError)?; @@ -178,7 +178,7 @@ impl ADBMessageDevice { } pub(crate) fn stat_with_explicit_ids(&mut self, remote_path: &str) -> Result { - let stat_buffer = MessageSubcommand::Stat.with_arg(remote_path.len() as u32); + let stat_buffer = MessageSubcommand::Stat.with_arg(u32::try_from(remote_path.len())?); let message = ADBTransportMessage::new( MessageCommand::Write, self.get_local_id()?, diff --git a/adb_client/src/device/adb_message_device_commands.rs b/adb_client/src/device/adb_message_device_commands.rs index 78b9e02..994676e 100644 --- a/adb_client/src/device/adb_message_device_commands.rs +++ b/adb_client/src/device/adb_message_device_commands.rs @@ -11,7 +11,7 @@ impl ADBDeviceExt for ADBMessageDevice { self.shell_command(command, output) } - fn shell(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()> { + fn shell(&mut self, reader: &mut dyn Read, writer: Box) -> Result<()> { self.shell(reader, writer) } diff --git a/adb_client/src/device/adb_tcp_device.rs b/adb_client/src/device/adb_tcp_device.rs index 5f2e8d3..96ad809 100644 --- a/adb_client/src/device/adb_tcp_device.rs +++ b/adb_client/src/device/adb_tcp_device.rs @@ -31,8 +31,8 @@ impl ADBTcpDevice { let message = ADBTransportMessage::new( MessageCommand::Cnxn, - 0x01000000, - 1048576, + 0x0100_0000, + 1_048_576, format!("host::{}\0", env!("CARGO_PKG_NAME")).as_bytes(), ); @@ -75,7 +75,7 @@ impl ADBDeviceExt for ADBTcpDevice { } #[inline] - fn shell(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()> { + fn shell(&mut self, reader: &mut dyn Read, writer: Box) -> Result<()> { self.inner.shell(reader, writer) } diff --git a/adb_client/src/device/adb_transport_message.rs b/adb_client/src/device/adb_transport_message.rs index d1ef0da..56a8753 100644 --- a/adb_client/src/device/adb_transport_message.rs +++ b/adb_client/src/device/adb_transport_message.rs @@ -58,12 +58,12 @@ impl ADBTransportMessageHeader { } pub(crate) fn compute_crc32(data: &[u8]) -> u32 { - data.iter().map(|&x| x as u32).sum() + data.iter().map(|&x| u32::from(x)).sum() } fn compute_magic(command: MessageCommand) -> u32 { let command_u32 = command as u32; - command_u32 ^ 0xFFFFFFFF + command_u32 ^ 0xFFFF_FFFF } pub fn as_bytes(&self) -> Result> { diff --git a/adb_client/src/device/adb_usb_device.rs b/adb_client/src/device/adb_usb_device.rs index 1de4376..83ee812 100644 --- a/adb_client/src/device/adb_usb_device.rs +++ b/adb_client/src/device/adb_usb_device.rs @@ -119,7 +119,7 @@ impl ADBUSBDevice { product_id: u16, private_key_path: PathBuf, ) -> 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. @@ -132,22 +132,21 @@ impl ADBUSBDevice { None => get_default_adb_key_path()?, }; - Self::new_from_transport_inner(transport, private_key_path) + Self::new_from_transport_inner(transport, &private_key_path) } fn new_from_transport_inner( transport: USBTransport, - private_key_path: PathBuf, + private_key_path: &PathBuf, ) -> Result { - let private_key = match read_adb_private_key(&private_key_path)? { - Some(pk) => pk, - None => { - log::warn!( - "No private key found at path {}. Using a temporary random one.", - private_key_path.display() - ); - ADBRsaKey::new_random()? - } + 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() + ); + ADBRsaKey::new_random()? }; let mut s = Self { @@ -183,8 +182,8 @@ impl ADBUSBDevice { let message = ADBTransportMessage::new( MessageCommand::Cnxn, - 0x01000000, - 1048576, + 0x0100_0000, + 1_048_576, format!("host::{}\0", env!("CARGO_PKG_NAME")).as_bytes(), ); @@ -260,7 +259,7 @@ impl ADBDeviceExt for ADBUSBDevice { } #[inline] - fn shell<'a>(&mut self, reader: &mut dyn Read, writer: Box<(dyn Write + Send)>) -> Result<()> { + fn shell<'a>(&mut self, reader: &mut dyn Read, writer: Box) -> Result<()> { self.inner.shell(reader, writer) } diff --git a/adb_client/src/device/commands/framebuffer.rs b/adb_client/src/device/commands/framebuffer.rs index d41422f..48b6507 100644 --- a/adb_client/src/device/commands/framebuffer.rs +++ b/adb_client/src/device/commands/framebuffer.rs @@ -32,7 +32,7 @@ impl ADBMessageDevice { payload_cursor.read_to_end(&mut framebuffer_data)?; loop { - if framebuffer_data.len() as u32 == framebuffer_info.size { + if u32::try_from(framebuffer_data.len())? == framebuffer_info.size { break; } @@ -65,7 +65,7 @@ impl ADBMessageDevice { payload_cursor.read_to_end(&mut framebuffer_data)?; loop { - if framebuffer_data.len() as u32 == framebuffer_info.size { + if u32::try_from(framebuffer_data.len())? == framebuffer_info.size { break; } diff --git a/adb_client/src/device/commands/pull.rs b/adb_client/src/device/commands/pull.rs index 9e5bc55..54898f3 100644 --- a/adb_client/src/device/commands/pull.rs +++ b/adb_client/src/device/commands/pull.rs @@ -29,7 +29,7 @@ impl ADBMessageDevice { std::time::Duration::from_secs(4), )?; - let recv_buffer = MessageSubcommand::Recv.with_arg(source.len() as u32); + let recv_buffer = MessageSubcommand::Recv.with_arg(u32::try_from(source.len())?); let recv_buffer = bincode::serialize(&recv_buffer).map_err(|_e| RustADBError::ConversionError)?; self.send_and_expect_okay(ADBTransportMessage::new( diff --git a/adb_client/src/device/commands/push.rs b/adb_client/src/device/commands/push.rs index d87ee7a..7b6d450 100644 --- a/adb_client/src/device/commands/push.rs +++ b/adb_client/src/device/commands/push.rs @@ -14,7 +14,7 @@ impl ADBMessageDevice { let path_header = format!("{},0777", path.as_ref()); - let send_buffer = MessageSubcommand::Send.with_arg(path_header.len() as u32); + let send_buffer = MessageSubcommand::Send.with_arg(u32::try_from(path_header.len())?); let mut send_buffer = bincode::serialize(&send_buffer).map_err(|_e| RustADBError::ConversionError)?; send_buffer.append(&mut path_header.as_bytes().to_vec()); diff --git a/adb_client/src/device/commands/shell.rs b/adb_client/src/device/commands/shell.rs index eea7097..895d928 100644 --- a/adb_client/src/device/commands/shell.rs +++ b/adb_client/src/device/commands/shell.rs @@ -36,7 +36,7 @@ impl ADBMessageDevice { pub(crate) fn shell( &mut self, mut reader: &mut dyn Read, - mut writer: Box<(dyn Write + Send)>, + mut writer: Box, ) -> Result<()> { self.open_session(b"shell:\0")?; @@ -60,7 +60,7 @@ impl ADBMessageDevice { writer.write_all(&message.into_payload())?; writer.flush()?; } - MessageCommand::Okay => continue, + MessageCommand::Okay => {} _ => return Err(RustADBError::ADBShellNotSupported), } } diff --git a/adb_client/src/device/models/adb_rsa_key.rs b/adb_client/src/device/models/adb_rsa_key.rs index 396f040..260886a 100644 --- a/adb_client/src/device/models/adb_rsa_key.rs +++ b/adb_client/src/device/models/adb_rsa_key.rs @@ -6,6 +6,7 @@ use num_traits::cast::ToPrimitive; use rsa::pkcs8::DecodePrivateKey; use rsa::traits::PublicKeyParts; use rsa::{Pkcs1v15Sign, RsaPrivateKey}; +use std::fmt::Write; const ADB_PRIVATE_KEY_SIZE: usize = 2048; const ANDROID_PUBKEY_MODULUS_SIZE_WORDS: u32 = 64; @@ -92,15 +93,16 @@ impl ADBRsaKey { .to_u32() .ok_or(RustADBError::ConversionError)?; - Ok(self.encode_public_key(adb_rsa_pubkey.into_bytes())) + Self::encode_public_key(adb_rsa_pubkey.into_bytes()) } - fn encode_public_key(&self, pub_key: Vec) -> String { + fn encode_public_key(pub_key: Vec) -> Result { let mut encoded = STANDARD.encode(pub_key); encoded.push(' '); - encoded.push_str(&format!("adb_client@{}", env!("CARGO_PKG_VERSION"))); + write!(encoded, "adb_client@{}", env!("CARGO_PKG_VERSION")) + .map_err(|_| RustADBError::ConversionError)?; - encoded + Ok(encoded) } pub fn sign(&self, msg: impl AsRef<[u8]>) -> Result> { diff --git a/adb_client/src/device/models/message_commands.rs b/adb_client/src/device/models/message_commands.rs index ff3918c..1603b89 100644 --- a/adb_client/src/device/models/message_commands.rs +++ b/adb_client/src/device/models/message_commands.rs @@ -6,32 +6,32 @@ use std::fmt::Display; #[repr(u32)] pub enum MessageCommand { /// Connect to a device - Cnxn = 0x4E584E43, + Cnxn = 0x4E58_4E43, /// Close connection to a device - Clse = 0x45534C43, + Clse = 0x4553_4C43, /// Device ask for authentication - Auth = 0x48545541, + Auth = 0x4854_5541, /// Open a data connection - Open = 0x4E45504F, + Open = 0x4E45_504F, /// Write data to connection - Write = 0x45545257, + Write = 0x4554_5257, /// Server understood the message - Okay = 0x59414B4F, + Okay = 0x5941_4B4F, /// Start a connection using TLS - Stls = 0x534C5453, + Stls = 0x534C_5453, } #[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize_repr, Deserialize_repr)] #[repr(u32)] pub enum MessageSubcommand { - Stat = 0x54415453, - Send = 0x444E4553, - Recv = 0x56434552, - Quit = 0x54495551, - Fail = 0x4C494146, - Done = 0x454E4F44, - Data = 0x41544144, - List = 0x5453494C, + Stat = 0x5441_5453, + Send = 0x444E_4553, + Recv = 0x5643_4552, + Quit = 0x5449_5551, + Fail = 0x4C49_4146, + Done = 0x454E_4F44, + Data = 0x4154_4144, + List = 0x5453_494C, } #[derive(Debug, Serialize, Deserialize)] diff --git a/adb_client/src/emulator_device/adb_emulator_device.rs b/adb_client/src/emulator_device/adb_emulator_device.rs index 9c3ec4f..60cfaa6 100644 --- a/adb_client/src/emulator_device/adb_emulator_device.rs +++ b/adb_client/src/emulator_device/adb_emulator_device.rs @@ -15,16 +15,16 @@ static EMULATOR_REGEX: LazyLock = LazyLock::new(|| { pub struct ADBEmulatorDevice { /// Unique device identifier. pub identifier: String, - /// Internal [TCPEmulatorTransport] + /// Internal [`TCPEmulatorTransport`] transport: TCPEmulatorTransport, } impl ADBEmulatorDevice { - /// Instantiates a new [ADBEmulatorDevice] + /// Instantiates a new [`ADBEmulatorDevice`] pub fn new(identifier: String, ip_address: Option) -> Result { let ip_address = match ip_address { Some(ip_address) => ip_address, - None => Ipv4Addr::new(127, 0, 0, 1), + None => Ipv4Addr::LOCALHOST, }; let groups = EMULATOR_REGEX diff --git a/adb_client/src/emulator_device/models/adb_emulator_command.rs b/adb_client/src/emulator_device/models/adb_emulator_command.rs index 55f6e91..a20dab0 100644 --- a/adb_client/src/emulator_device/models/adb_emulator_command.rs +++ b/adb_client/src/emulator_device/models/adb_emulator_command.rs @@ -24,8 +24,7 @@ impl ADBEmulatorCommand { pub(crate) fn skip_response_lines(&self) -> u8 { match self { ADBEmulatorCommand::Authenticate(_) => 1, - ADBEmulatorCommand::Sms(_, _) => 0, - ADBEmulatorCommand::Rotate => 0, + ADBEmulatorCommand::Sms(_, _) | ADBEmulatorCommand::Rotate => 0, } } } diff --git a/adb_client/src/error.rs b/adb_client/src/error.rs index 0164211..17997bb 100644 --- a/adb_client/src/error.rs +++ b/adb_client/src/error.rs @@ -42,6 +42,9 @@ pub enum RustADBError { /// Indicates that an error occurred when converting a value. #[error("Conversion error")] ConversionError, + /// Indicates an error with the integer conversion. + #[error(transparent)] + IntegerConversionError(#[from] std::num::TryFromIntError), /// Remote ADB server does not support shell feature. #[error("Remote ADB server does not support shell feature")] ADBShellNotSupported, diff --git a/adb_client/src/mdns/mdns_discovery.rs b/adb_client/src/mdns/mdns_discovery.rs index 39b4e67..3a84e88 100644 --- a/adb_client/src/mdns/mdns_discovery.rs +++ b/adb_client/src/mdns/mdns_discovery.rs @@ -42,7 +42,6 @@ impl MDNSDiscoveryService { | ServiceEvent::ServiceFound(_, _) | ServiceEvent::SearchStopped(_) => { // Ignoring these events. We are only interesting in found devices - continue; } ServiceEvent::ServiceResolved(service_info) => { if let Err(e) = sender.send(MDNSDevice::from(service_info)) { diff --git a/adb_client/src/server/adb_server.rs b/adb_client/src/server/adb_server.rs index 33b7987..783f721 100644 --- a/adb_client/src/server/adb_server.rs +++ b/adb_client/src/server/adb_server.rs @@ -9,7 +9,7 @@ use std::process::Command; /// Represents an ADB Server #[derive(Debug, Default)] pub struct ADBServer { - /// Internal [TcpStream], lazily initialized + /// Internal [`TcpStream`], lazily initialized pub(crate) transport: Option, /// Address to connect to pub(crate) socket_addr: Option, @@ -21,7 +21,7 @@ pub struct ADBServer { } impl ADBServer { - /// Instantiates a new [ADBServer] + /// Instantiates a new [`ADBServer`] pub fn new(address: SocketAddrV4) -> Self { Self { transport: None, @@ -31,7 +31,7 @@ impl ADBServer { } } - /// Instantiates a new [ADBServer] with a custom adb path + /// Instantiates a new [`ADBServer`] with a custom adb path pub fn new_from_path(address: SocketAddrV4, adb_path: Option) -> Self { Self { transport: None, @@ -46,7 +46,7 @@ impl ADBServer { // ADB Server is local, we start it if not already running let mut command = Command::new(adb_path.as_deref().unwrap_or("adb")); command.arg("start-server"); - for (env_k, env_v) in envs.iter() { + for (env_k, env_v) in envs { command.env(env_k, env_v); } @@ -61,7 +61,7 @@ impl ADBServer { match child { Ok(mut child) => { if let Err(e) = child.wait() { - log::error!("error while starting adb server: {e}") + log::error!("error while starting adb server: {e}"); } } Err(e) => log::error!("error while starting adb server: {e}"), diff --git a/adb_client/src/server/commands/devices.rs b/adb_client/src/server/commands/devices.rs index 9c4dc2c..d930974 100644 --- a/adb_client/src/server/commands/devices.rs +++ b/adb_client/src/server/commands/devices.rs @@ -69,12 +69,12 @@ impl ADBServer { .filter(|d| d.identifier.as_str() == name) .collect::>() .len(); - if nb_devices != 1 { + if nb_devices == 1 { + Ok(ADBServerDevice::new(name.to_string(), self.socket_addr)) + } else { Err(RustADBError::DeviceNotFound(format!( "could not find device {name}" ))) - } else { - Ok(ADBServerDevice::new(name.to_string(), self.socket_addr)) } } diff --git a/adb_client/src/server/models/adb_version.rs b/adb_client/src/server/models/adb_version.rs index 07cb4b1..def13c4 100644 --- a/adb_client/src/server/models/adb_version.rs +++ b/adb_client/src/server/models/adb_version.rs @@ -15,7 +15,7 @@ pub struct AdbVersion { } impl AdbVersion { - /// Instantiates a new [AdbVersion]. + /// Instantiates a new [`AdbVersion`]. pub fn new(minor: u32, revision: u32) -> Self { Self { major: 1, diff --git a/adb_client/src/server/models/device_long.rs b/adb_client/src/server/models/device_long.rs index 3174690..6b8c92d 100644 --- a/adb_client/src/server/models/device_long.rs +++ b/adb_client/src/server/models/device_long.rs @@ -86,15 +86,13 @@ impl TryFrom<&[u8]> for DeviceLong { None => "Unk".to_string(), Some(device) => String::from_utf8(device.as_bytes().to_vec())?, }, - transport_id: u32::from_str_radix( - str::from_utf8( - groups - .name("transport_id") - .ok_or(RustADBError::RegexParsingError)? - .as_bytes(), - )?, - 10, - )?, + transport_id: (str::from_utf8( + groups + .name("transport_id") + .ok_or(RustADBError::RegexParsingError)? + .as_bytes(), + )?) + .parse::()?, }) } } diff --git a/adb_client/src/server/models/server_status.rs b/adb_client/src/server/models/server_status.rs index a00ff1f..aeaf0cc 100644 --- a/adb_client/src/server/models/server_status.rs +++ b/adb_client/src/server/models/server_status.rs @@ -48,11 +48,11 @@ impl Display for UsbBackend { #[derive(Debug, Clone, PartialEq, Default)] pub enum MDNSBackend { #[default] - /// Unknown + /// `Unknown` Unknown = 0, - /// Bonjour + /// `Bonjour` Bonjour = 1, - /// OpenScreen + /// `OpenScreen` OpenScreen = 2, } diff --git a/adb_client/src/server_device/adb_server_device.rs b/adb_client/src/server_device/adb_server_device.rs index 1c8d480..89d0ae2 100644 --- a/adb_client/src/server_device/adb_server_device.rs +++ b/adb_client/src/server_device/adb_server_device.rs @@ -6,12 +6,12 @@ use std::net::SocketAddrV4; pub struct ADBServerDevice { /// Unique device identifier. pub identifier: Option, - /// Internal [TCPServerTransport] + /// Internal [`TCPServerTransport`] pub(crate) transport: TCPServerTransport, } impl ADBServerDevice { - /// Instantiates a new [ADBServerDevice], knowing its ADB identifier (as returned by `adb devices` command). + /// Instantiates a new [`ADBServerDevice`], knowing its ADB identifier (as returned by `adb devices` command). pub fn new(identifier: String, server_addr: Option) -> Self { let transport = TCPServerTransport::new_or_default(server_addr); @@ -21,7 +21,7 @@ impl ADBServerDevice { } } - /// Instantiates a new [ADBServerDevice], assuming only one is currently connected. + /// Instantiates a new [`ADBServerDevice`], assuming only one is currently connected. pub fn autodetect(server_addr: Option) -> Self { let transport = TCPServerTransport::new_or_default(server_addr); diff --git a/adb_client/src/server_device/adb_server_device_commands.rs b/adb_client/src/server_device/adb_server_device_commands.rs index af276ed..ca2c938 100644 --- a/adb_client/src/server_device/adb_server_device_commands.rs +++ b/adb_client/src/server_device/adb_server_device_commands.rs @@ -25,15 +25,14 @@ impl ADBDeviceExt for ADBServerDevice { self.transport .send_adb_request(AdbServerCommand::ShellCommand(command.join(" ")))?; + let mut buffer = vec![0; BUFFER_SIZE].into_boxed_slice(); loop { - let mut buffer = [0; BUFFER_SIZE]; match self.transport.get_raw_connection()?.read(&mut buffer) { Ok(size) => { if size == 0 { return Ok(()); - } else { - output.write_all(&buffer[..size])?; } + output.write_all(&buffer[..size])?; } Err(e) => { return Err(RustADBError::IOError(e)); @@ -49,7 +48,7 @@ impl ADBDeviceExt for ADBServerDevice { fn shell( &mut self, mut reader: &mut dyn Read, - mut writer: Box<(dyn Write + Send)>, + mut writer: Box, ) -> Result<()> { let supported_features = self.host_features()?; if !supported_features.contains(&HostFeatures::ShellV2) @@ -67,8 +66,9 @@ impl ADBDeviceExt for ADBServerDevice { // Reading thread, reads response from adb-server std::thread::spawn(move || -> Result<()> { + let mut buffer = vec![0; BUFFER_SIZE].into_boxed_slice(); + loop { - let mut buffer = [0; BUFFER_SIZE]; match read_stream.read(&mut buffer) { Ok(0) => { read_stream.shutdown(std::net::Shutdown::Both)?; diff --git a/adb_client/src/server_device/commands/list.rs b/adb_client/src/server_device/commands/list.rs index 54ceb02..abdfcc1 100644 --- a/adb_client/src/server_device/commands/list.rs +++ b/adb_client/src/server_device/commands/list.rs @@ -26,7 +26,7 @@ impl ADBServerDevice { // 'DONE' directly without listing anything. fn handle_list_command>(&mut self, path: S) -> Result<()> { let mut len_buf = [0_u8; 4]; - LittleEndian::write_u32(&mut len_buf, path.as_ref().len() as u32); + LittleEndian::write_u32(&mut len_buf, u32::try_from(path.as_ref().len())?); // 4 bytes of command name is already sent by send_sync_request self.transport.get_raw_connection()?.write_all(&len_buf)?; diff --git a/adb_client/src/server_device/commands/recv.rs b/adb_client/src/server_device/commands/recv.rs index d20fcee..ae4b9dd 100644 --- a/adb_client/src/server_device/commands/recv.rs +++ b/adb_client/src/server_device/commands/recv.rs @@ -5,7 +5,7 @@ use crate::{ use byteorder::{LittleEndian, ReadBytesExt}; use std::io::{BufReader, BufWriter, Read, Write}; -/// Internal structure wrapping a [std::io::Read] and hiding underlying protocol logic. +/// Internal structure wrapping a [`std::io::Read`] and hiding underlying protocol logic. struct ADBRecvCommandReader { inner: R, remaining_data_bytes_to_read: usize, @@ -86,7 +86,7 @@ impl ADBServerDevice { let from_as_bytes = from.as_ref().as_bytes(); let mut buffer = Vec::with_capacity(4 + from_as_bytes.len()); - buffer.extend_from_slice(&(from.as_ref().len() as u32).to_le_bytes()); + buffer.extend_from_slice(&(u32::try_from(from.as_ref().len())?).to_le_bytes()); buffer.extend_from_slice(from_as_bytes); raw_connection.write_all(&buffer)?; diff --git a/adb_client/src/server_device/commands/send.rs b/adb_client/src/server_device/commands/send.rs index 3454c7e..9cf8b57 100644 --- a/adb_client/src/server_device/commands/send.rs +++ b/adb_client/src/server_device/commands/send.rs @@ -9,7 +9,7 @@ use std::{ time::SystemTime, }; -/// Internal structure wrapping a [std::io::Write] and hiding underlying protocol logic. +/// Internal structure wrapping a [`std::io::Write`] and hiding underlying protocol logic. struct ADBSendCommandWriter { inner: W, } @@ -64,7 +64,7 @@ impl ADBServerDevice { // The name of the command is already sent by get_transport()?.send_sync_request let to_as_bytes = to.as_bytes(); let mut buffer = Vec::with_capacity(4 + to_as_bytes.len()); - buffer.extend_from_slice(&(to.len() as u32).to_le_bytes()); + buffer.extend_from_slice(&(u32::try_from(to.len())?).to_le_bytes()); buffer.extend_from_slice(to_as_bytes); raw_connection.write_all(&buffer)?; @@ -77,9 +77,10 @@ impl ADBServerDevice { // Copy is finished, we can now notify as finished // Have to send DONE + file mtime - let last_modified = match SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) { - Ok(n) => n, - Err(_) => panic!("SystemTime before UNIX EPOCH!"), + let Ok(last_modified) = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH) else { + return Err(RustADBError::ADBRequestFailed( + "SystemTime before UNIX EPOCH!".into(), + )); }; let mut done_buffer = Vec::with_capacity(8); diff --git a/adb_client/src/server_device/commands/stat.rs b/adb_client/src/server_device/commands/stat.rs index 8e107fa..3d4f428 100644 --- a/adb_client/src/server_device/commands/stat.rs +++ b/adb_client/src/server_device/commands/stat.rs @@ -10,7 +10,7 @@ use crate::{ impl ADBServerDevice { fn handle_stat_command>(&mut self, path: S) -> Result { let mut len_buf = [0_u8; 4]; - LittleEndian::write_u32(&mut len_buf, path.as_ref().len() as u32); + LittleEndian::write_u32(&mut len_buf, u32::try_from(path.as_ref().len())?); // 4 bytes of command name is already sent by send_sync_request self.transport.get_raw_connection()?.write_all(&len_buf)?; diff --git a/adb_client/src/transports/tcp_emulator_transport.rs b/adb_client/src/transports/tcp_emulator_transport.rs index 9a31542..1b99f5f 100644 --- a/adb_client/src/transports/tcp_emulator_transport.rs +++ b/adb_client/src/transports/tcp_emulator_transport.rs @@ -17,7 +17,7 @@ pub struct TCPEmulatorTransport { } impl TCPEmulatorTransport { - /// Instantiates a new instance of [TCPEmulatorTransport] + /// Instantiates a new instance of [`TCPEmulatorTransport`] pub fn new(socket_addr: SocketAddrV4) -> Self { Self { socket_addr, @@ -34,11 +34,10 @@ impl TCPEmulatorTransport { ))) } - /// Return authentication token stored in $HOME/.emulator_console_auth_token + /// Return authentication token stored in `$HOME/.emulator_console_auth_token` pub fn get_authentication_token(&mut self) -> Result { - let home = match my_home()? { - Some(home) => home, - None => return Err(RustADBError::NoHomeDirectory), + let Some(home) = my_home()? else { + return Err(RustADBError::NoHomeDirectory); }; let mut f = File::open(home.join(".emulator_console_auth_token"))?; @@ -54,7 +53,7 @@ impl TCPEmulatorTransport { self.send_command(ADBEmulatorCommand::Authenticate(token)) } - /// Send an [ADBEmulatorCommand] to this emulator + /// Send an [`ADBEmulatorCommand`] to this emulator pub(crate) fn send_command(&mut self, command: ADBEmulatorCommand) -> Result<()> { let mut connection = self.get_raw_connection()?; @@ -80,10 +79,11 @@ impl TCPEmulatorTransport { let mut line = String::new(); reader.read_line(&mut line)?; - match line.starts_with("OK") { - true => Ok(()), - false => Err(RustADBError::ADBRequestFailed(line)), + if line.starts_with("OK") { + return Ok(()); } + + Err(RustADBError::ADBRequestFailed(line)) } } diff --git a/adb_client/src/transports/tcp_server_transport.rs b/adb_client/src/transports/tcp_server_transport.rs index 0b0c29b..20cac72 100644 --- a/adb_client/src/transports/tcp_server_transport.rs +++ b/adb_client/src/transports/tcp_server_transport.rs @@ -8,7 +8,7 @@ use crate::models::{AdbRequestStatus, SyncCommand}; use crate::{ADBTransport, models::AdbServerCommand}; use crate::{Result, RustADBError}; -const DEFAULT_SERVER_IP: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1); +const DEFAULT_SERVER_IP: Ipv4Addr = Ipv4Addr::LOCALHOST; const DEFAULT_SERVER_PORT: u16 = 5037; /// Server transport running on top on TCP @@ -25,7 +25,7 @@ impl Default for TCPServerTransport { } impl TCPServerTransport { - /// Instantiates a new instance of [TCPServerTransport] + /// Instantiates a new instance of [`TCPServerTransport`] pub fn new(socket_addr: SocketAddrV4) -> Self { Self { socket_addr, @@ -33,7 +33,7 @@ impl TCPServerTransport { } } - /// Instantiate a new instance of [TCPServerTransport] using given address, or default if not specified. + /// Instantiate a new instance of [`TCPServerTransport`] using given address, or default if not specified. pub fn new_or_default(socket_addr: Option) -> Self { match socket_addr { Some(s) => Self::new(s), @@ -41,7 +41,7 @@ impl TCPServerTransport { } } - /// Get underlying [SocketAddrV4] + /// Get underlying [`SocketAddrV4`] pub fn get_socketaddr(&self) -> SocketAddrV4 { self.socket_addr } @@ -89,7 +89,7 @@ impl TCPServerTransport { )?) } - /// Send the given [SyncCommand] to ADB server, and checks that the request has been taken in consideration. + /// 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<()> { // First 4 bytes are the name of the command we want to send // (e.g. "SEND", "RECV", "STAT", "LIST") @@ -98,7 +98,7 @@ impl TCPServerTransport { .write_all(command.to_string().as_bytes())?) } - /// Gets the body length from a LittleEndian value + /// Gets the body length from a `LittleEndian` value pub(crate) fn get_body_length(&self) -> Result { let length_buffer = self.read_body_length()?; Ok(LittleEndian::read_u32(&length_buffer)) @@ -112,8 +112,8 @@ impl TCPServerTransport { Ok(length_buffer) } - /// Send the given [AdbCommand] to ADB server, and checks that the request has been taken in consideration. - /// If an error occurred, a [RustADBError] is returned with the response error string. + /// Send the given [`AdbCommand`] to ADB server, and checks that the request has been taken in consideration. + /// If an error occurred, a [`RustADBError`] is returned with the response error string. pub(crate) fn send_adb_request(&mut self, command: AdbServerCommand) -> Result<()> { let adb_command_string = command.to_string(); let adb_request = format!("{:04x}{}", adb_command_string.len(), adb_command_string); diff --git a/adb_client/src/transports/tcp_transport.rs b/adb_client/src/transports/tcp_transport.rs index 95e5484..d420b28 100644 --- a/adb_client/src/transports/tcp_transport.rs +++ b/adb_client/src/transports/tcp_transport.rs @@ -16,7 +16,6 @@ use std::{ fs::read_to_string, io::{Read, Write}, net::{Shutdown, SocketAddr, TcpStream}, - ops::{Deref, DerefMut}, path::PathBuf, sync::{Arc, Mutex}, time::Duration, @@ -120,18 +119,15 @@ impl TcpTransport { } pub(crate) fn upgrade_connection(&mut self) -> Result<()> { - let current_connection = match self.current_connection.clone() { - Some(current_connection) => current_connection, - None => { - return Err(RustADBError::UpgradeError( - "cannot upgrade a non-existing connection...".into(), - )); - } + let Some(current_connection) = self.current_connection.clone() else { + return Err(RustADBError::UpgradeError( + "cannot upgrade a non-existing connection...".into(), + )); }; { let mut current_conn_locked = current_connection.lock()?; - match current_conn_locked.deref() { + match &*current_conn_locked { CurrentConnection::Tcp(tcp_stream) => { // TODO: Check if we cannot be more precise @@ -192,7 +188,7 @@ impl ADBTransport for TcpTransport { log::debug!("disconnecting..."); if let Some(current_connection) = &self.current_connection { let mut lock = current_connection.lock()?; - match lock.deref_mut() { + match &mut *lock { CurrentConnection::Tcp(tcp_stream) => { let _ = tcp_stream.shutdown(Shutdown::Both); } diff --git a/adb_client/src/transports/usb_transport.rs b/adb_client/src/transports/usb_transport.rs index 9f536cb..5310486 100644 --- a/adb_client/src/transports/usb_transport.rs +++ b/adb_client/src/transports/usb_transport.rs @@ -29,7 +29,7 @@ pub struct USBTransport { impl USBTransport { /// Instantiate a new [`USBTransport`]. - /// Only the first device with given vendor_id and product_id is returned. + /// Only the first device with given `vendor_id` and `product_id` is returned. pub fn new(vendor_id: u16, product_id: u16) -> Result { for device in rusb::devices()?.iter() { if let Ok(descriptor) = device.device_descriptor() { @@ -90,14 +90,13 @@ impl USBTransport { Ok(()) } - fn find_endpoints(&self, handle: &DeviceHandle) -> Result<(Endpoint, Endpoint)> { + fn find_endpoints(handle: &DeviceHandle) -> Result<(Endpoint, Endpoint)> { let mut read_endpoint: Option = None; let mut write_endpoint: Option = None; for n in 0..handle.device().device_descriptor()?.num_configurations() { - let config_desc = match handle.device().config_descriptor(n) { - Ok(c) => c, - Err(_) => continue, + let Ok(config_desc) = handle.device().config_descriptor(n) else { + continue; }; for interface in config_desc.interfaces() { @@ -117,16 +116,14 @@ impl USBTransport { Direction::In => { if let Some(write_endpoint) = write_endpoint { return Ok((endpoint, write_endpoint)); - } else { - read_endpoint = Some(endpoint); } + read_endpoint = Some(endpoint); } Direction::Out => { if let Some(read_endpoint) = read_endpoint { return Ok((read_endpoint, endpoint)); - } else { - write_endpoint = Some(endpoint); } + write_endpoint = Some(endpoint); } } } @@ -150,7 +147,7 @@ impl USBTransport { let write_amount = handle.write_bulk(endpoint.address, &data[offset..end], timeout)?; offset += write_amount; - log::trace!("wrote chunk of size {write_amount} - {offset}/{data_len}",) + log::trace!("wrote chunk of size {write_amount} - {offset}/{data_len}",); } if offset % max_packet_size == 0 { @@ -166,7 +163,7 @@ impl ADBTransport for USBTransport { fn connect(&mut self) -> crate::Result<()> { let device = self.device.open()?; - let (read_endpoint, write_endpoint) = self.find_endpoints(&device)?; + let (read_endpoint, write_endpoint) = Self::find_endpoints(&device)?; Self::configure_endpoint(&device, &read_endpoint)?; log::debug!("got read endpoint: {read_endpoint:?}"); diff --git a/pyadb_client/Cargo.toml b/pyadb_client/Cargo.toml index cecce2a..4df1adb 100644 --- a/pyadb_client/Cargo.toml +++ b/pyadb_client/Cargo.toml @@ -21,7 +21,7 @@ name = "stub_gen" [dependencies] adb_client = { path = "../adb_client" } -anyhow = { version = "1.0.95" } -pyo3 = { version = "0.25.0", features = ["abi3-py37", "anyhow"] } +anyhow = { version = "1.0.100" } +pyo3 = { version = "0.25.1", features = ["abi3-py37", "anyhow"] } pyo3-stub-gen = "0.7.0" pyo3-stub-gen-derive = "0.7.0" diff --git a/pyadb_client/src/adb_server.rs b/pyadb_client/src/adb_server.rs index abea3cd..d3fb706 100644 --- a/pyadb_client/src/adb_server.rs +++ b/pyadb_client/src/adb_server.rs @@ -16,7 +16,7 @@ pub struct PyADBServer(ADBServer); #[pymethods] impl PyADBServer { #[new] - /// Instantiate a new PyADBServer instance + /// Instantiate a new `PyADBServer` instance pub fn new(address: String) -> PyResult { let address = address.parse::()?; Ok(ADBServer::new(address).into()) @@ -24,7 +24,12 @@ impl PyADBServer { /// List available devices pub fn devices(&mut self) -> Result> { - Ok(self.0.devices()?.into_iter().map(|v| v.into()).collect()) + Ok(self + .0 + .devices()? + .into_iter() + .map(std::convert::Into::into) + .collect()) } /// Get a device, assuming that only one is currently connected