serialport/posix/
error.rs

1use std::io;
2
3use crate::{Error, ErrorKind};
4
5#[cfg(all(target_os = "linux", not(target_env = "musl"), feature = "libudev"))]
6impl From<libudev::Error> for Error {
7    fn from(e: libudev::Error) -> Error {
8        use libudev::ErrorKind as K;
9        let kind = match e.kind() {
10            K::NoMem => ErrorKind::Unknown,
11            K::InvalidInput => ErrorKind::InvalidInput,
12            K::Io(a) => ErrorKind::Io(a),
13        };
14        Error::new(kind, e.description())
15    }
16}
17
18impl From<nix::Error> for Error {
19    fn from(e: nix::Error) -> Error {
20        use io::ErrorKind as IO;
21        use nix::errno::Errno as E;
22        use ErrorKind as K;
23        let kind = match e {
24            E::ETIMEDOUT => K::Io(IO::TimedOut),
25            E::ECONNABORTED => K::Io(IO::ConnectionAborted),
26            E::ECONNRESET => K::Io(IO::ConnectionReset),
27            E::ECONNREFUSED => K::Io(IO::ConnectionRefused),
28            E::ENOTCONN => K::Io(IO::NotConnected),
29            E::EADDRINUSE => K::Io(IO::AddrInUse),
30            E::EADDRNOTAVAIL => K::Io(IO::AddrNotAvailable),
31            E::EAGAIN => K::Io(IO::WouldBlock),
32            E::EINTR => K::Io(IO::Interrupted),
33            E::EACCES => K::Io(IO::PermissionDenied),
34            E::ENOENT => K::Io(IO::NotFound),
35            _ => K::Unknown,
36        };
37        Error::new(kind, e.desc())
38    }
39}