1use std::io;
2
3#[derive(Debug)]
5pub enum Error {
6 Io(io::Error),
8 Adb(String),
10 Protocol(String),
12}
13
14impl std::fmt::Display for Error {
15 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
16 match self {
17 Error::Io(e) => write!(f, "io: {e}"),
18 Error::Adb(msg) => write!(f, "adb: {msg}"),
19 Error::Protocol(msg) => write!(f, "protocol: {msg}"),
20 }
21 }
22}
23
24impl std::error::Error for Error {
25 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
26 match self {
27 Error::Io(e) => Some(e),
28 _ => None,
29 }
30 }
31}
32
33impl From<io::Error> for Error {
34 fn from(e: io::Error) -> Self {
35 Error::Io(e)
36 }
37}
38
39impl Error {
40 pub(crate) fn timed_out(msg: &str) -> Self {
41 Error::Io(io::Error::new(io::ErrorKind::TimedOut, msg))
42 }
43}
44
45pub type Result<T> = std::result::Result<T, Error>;