chore: clippy improvements
This commit is contained in:
@@ -110,7 +110,7 @@ fn run_command(mut device: Box<dyn ADBDeviceExt>, command: DeviceCommands) -> AD
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
if let Err(err) = _main() {
|
||||
if let Err(err) = inner_main() {
|
||||
log::error!("{err}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ fn main() -> ExitCode {
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
|
||||
fn _main() -> ADBCliResult<()> {
|
||||
fn inner_main() -> ADBCliResult<()> {
|
||||
// This depends on `clap`
|
||||
let opts = Opts::parse();
|
||||
|
||||
|
||||
@@ -36,12 +36,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
/// payload Wanted in
|
||||
/// Next payload
|
||||
fn read_bytes_from_transport(
|
||||
requested_bytes: &usize,
|
||||
requested_bytes: usize,
|
||||
current_index: &mut usize,
|
||||
transport: &mut T,
|
||||
payload: &mut Vec<u8>,
|
||||
local_id: &u32,
|
||||
remote_id: &u32,
|
||||
local_id: u32,
|
||||
remote_id: u32,
|
||||
) -> Result<Vec<u8>> {
|
||||
if *current_index + requested_bytes <= payload.len() {
|
||||
// if there is enough bytes in this payload
|
||||
@@ -59,7 +59,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
|
||||
// Request the next message
|
||||
let send_message =
|
||||
ADBTransportMessage::new(MessageCommand::Okay, *local_id, *remote_id, &[]);
|
||||
ADBTransportMessage::new(MessageCommand::Okay, local_id, remote_id, &[]);
|
||||
transport.write_message(send_message)?;
|
||||
// Read the new message
|
||||
*payload = transport.read_message()?.into_payload();
|
||||
@@ -80,7 +80,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
// SEE: https://github.com/cstyan/adbDocumentation?tab=readme-ov-file#adb-list
|
||||
{
|
||||
let mut len_buf = Vec::from([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())?);
|
||||
|
||||
let subcommand_data = MessageSubcommand::List;
|
||||
|
||||
@@ -109,12 +109,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
// Loop though the response for all the entries
|
||||
const STATUS_CODE_LENGTH_IN_BYTES: usize = 4;
|
||||
let status_code = Self::read_bytes_from_transport(
|
||||
&STATUS_CODE_LENGTH_IN_BYTES,
|
||||
STATUS_CODE_LENGTH_IN_BYTES,
|
||||
&mut current_index,
|
||||
transport,
|
||||
&mut payload,
|
||||
&local_id,
|
||||
&remote_id,
|
||||
local_id,
|
||||
remote_id,
|
||||
)?;
|
||||
match str::from_utf8(&status_code)? {
|
||||
"DENT" => {
|
||||
@@ -122,12 +122,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
const U32_SIZE_IN_BYTES: usize = 4;
|
||||
const SIZE_OF_METADATA: usize = U32_SIZE_IN_BYTES * 4;
|
||||
let metadata = Self::read_bytes_from_transport(
|
||||
&SIZE_OF_METADATA,
|
||||
SIZE_OF_METADATA,
|
||||
&mut current_index,
|
||||
transport,
|
||||
&mut payload,
|
||||
&local_id,
|
||||
&remote_id,
|
||||
local_id,
|
||||
remote_id,
|
||||
)?;
|
||||
let mode = metadata[..U32_SIZE_IN_BYTES].to_vec();
|
||||
let size = metadata[U32_SIZE_IN_BYTES..2 * U32_SIZE_IN_BYTES].to_vec();
|
||||
@@ -140,12 +140,12 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
let name_len = LittleEndian::read_u32(&name_len) as usize;
|
||||
// Read the file name, since it requires the length from the name_len
|
||||
let name_buf = Self::read_bytes_from_transport(
|
||||
&name_len,
|
||||
name_len,
|
||||
&mut current_index,
|
||||
transport,
|
||||
&mut payload,
|
||||
&local_id,
|
||||
&remote_id,
|
||||
local_id,
|
||||
remote_id,
|
||||
)?;
|
||||
let name = String::from_utf8(name_buf)?;
|
||||
|
||||
@@ -170,7 +170,7 @@ impl<T: ADBMessageTransport> ADBMessageDevice<T> {
|
||||
"DONE" => {
|
||||
return Ok(list_items);
|
||||
}
|
||||
x => log::error!("Got an unknown response {}", x),
|
||||
x => log::error!("Got an unknown response {x}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/// Represent a session between an ADBDevice and remote `adbd`.
|
||||
/// Represent a session between an `ADBDevice` and remote `adbd`.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(crate) struct ADBSession {
|
||||
local_id: u32,
|
||||
|
||||
@@ -22,6 +22,7 @@ pub struct ADBServer {
|
||||
|
||||
impl ADBServer {
|
||||
/// Instantiates a new [`ADBServer`]
|
||||
#[must_use]
|
||||
pub fn new(address: SocketAddrV4) -> Self {
|
||||
Self {
|
||||
transport: None,
|
||||
@@ -32,6 +33,7 @@ impl ADBServer {
|
||||
}
|
||||
|
||||
/// Instantiates a new [`ADBServer`] with a custom adb path
|
||||
#[must_use]
|
||||
pub fn new_from_path(address: SocketAddrV4, adb_path: Option<String>) -> Self {
|
||||
Self {
|
||||
transport: None,
|
||||
|
||||
@@ -12,6 +12,7 @@ pub struct ADBServerDevice {
|
||||
|
||||
impl ADBServerDevice {
|
||||
/// Instantiates a new [`ADBServerDevice`], knowing its ADB identifier (as returned by `adb devices` command).
|
||||
#[must_use]
|
||||
pub fn new(identifier: String, server_addr: Option<SocketAddrV4>) -> Self {
|
||||
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||
|
||||
@@ -22,6 +23,7 @@ impl ADBServerDevice {
|
||||
}
|
||||
|
||||
/// Instantiates a new [`ADBServerDevice`], assuming only one is currently connected.
|
||||
#[must_use]
|
||||
pub fn autodetect(server_addr: Option<SocketAddrV4>) -> Self {
|
||||
let transport = TCPServerTransport::new_or_default(server_addr);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::{
|
||||
};
|
||||
use std::{
|
||||
convert::TryInto,
|
||||
io::{BufReader, BufWriter, Read, Write},
|
||||
io::{self, BufReader, BufWriter, Read, Write},
|
||||
str::{self, FromStr},
|
||||
time::SystemTime,
|
||||
};
|
||||
@@ -22,7 +22,7 @@ impl<W: Write> ADBSendCommandWriter<W> {
|
||||
|
||||
impl<W: Write> Write for ADBSendCommandWriter<W> {
|
||||
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
||||
let chunk_len = buf.len() as u32;
|
||||
let chunk_len = u32::try_from(buf.len()).map_err(io::Error::other)?;
|
||||
|
||||
// 8 = "DATA".len() + sizeof(u32)
|
||||
let mut buffer = Vec::with_capacity(8 + buf.len());
|
||||
|
||||
@@ -26,6 +26,7 @@ impl Default for TCPServerTransport {
|
||||
|
||||
impl TCPServerTransport {
|
||||
/// Instantiates a new instance of [`TCPServerTransport`]
|
||||
#[must_use]
|
||||
pub fn new(socket_addr: SocketAddrV4) -> Self {
|
||||
Self {
|
||||
socket_addr,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# pyadb_client
|
||||
# `pyadb_client`
|
||||
|
||||
<p align="center">
|
||||
<p align="center">Python library to communicate with ADB devices. Built on top of Rust adb_client library.</p>
|
||||
|
||||
Reference in New Issue
Block a user