adb_client
adb_client copied to clipboard
Hi, i need help with adb_client ,thanks
let connexion = AdbTcpConnexion::new();
let callback = |device:adb_client::Device| {
println!("{}", device);
Ok(())
};
println!("Live list of devices attached");
connexion.track_devices(callback)?;
system Env:
System: Macos 12.3.1
rust version: 1.59.0
Android Debug Bridge version 1.0.41
impl TryFrom<Vec<u8>> for Device {
type Error = RustADBError;
// TODO: Prevent regex compilation every call to try_from()
fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
// Optional final '\n' is used to match TrackDevices inputs
let parse_regex = Regex::new("^(\\w+)\t(\\w+)\n?$")?;
let groups = match parse_regex.captures(&value).unwrap() // <----------- device.rs:29:51
Ok(Device {
identifier: String::from_utf8(
groups
.get(1)
.ok_or(RustADBError::RegexParsingError)?
.as_bytes()
.to_vec(),
)?,
state: DeviceState::from_str(&String::from_utf8(
groups
.get(2)
.ok_or(RustADBError::RegexParsingError)?
.as_bytes()
.to_vec(),
)?)?,
})
}
}
error output:
Live list of devices attached
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /Users/x/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/adb_client-0.2.0/src/models/device.rs:29:51
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
regex change to
// match space or \t
let parse_regex = Regex::new("^(\\w+)[ \t]+(\\w+)\n?$")?;
Can you provide me the output of your adb devices command ?
I met same problem, my output is something like this: 12345678 device product:123 model:123 device:123 transport_id:1
I met same problem, my output is something like this: 12345678 device product:123 model:123 device:123 transport_id:1
replace:
usb: String::from_utf8(
groups
.name("usb1")
.or_else(|| groups.name("usb2"))
.ok_or(RustADBError::RegexParsingError)?
.as_bytes()
.to_vec(),
)?,
with
usb: match groups.name("usb1") {
None => match groups.name("usb2") {
None => "Unk".to_string(),
Some(usb) => String::from_utf8(usb.as_bytes().to_vec())?,
},
Some(usb) => String::from_utf8(usb.as_bytes().to_vec())?,
},
Ok thanks for the report, I re-open. Feel free to open a PR for submitting this fix 😉
Fix in #37 !