serialport/posix/
error.rs1use 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::EBUSY => K::NoDevice,
29 E::ETIMEDOUT => K::Io(IO::TimedOut),
30 E::ECONNABORTED => K::Io(IO::ConnectionAborted),
31 E::ECONNRESET => K::Io(IO::ConnectionReset),
32 E::ECONNREFUSED => K::Io(IO::ConnectionRefused),
33 E::ENOTCONN => K::Io(IO::NotConnected),
34 E::EADDRINUSE => K::Io(IO::AddrInUse),
35 E::EADDRNOTAVAIL => K::Io(IO::AddrNotAvailable),
36 E::EAGAIN => K::Io(IO::WouldBlock),
37 E::EINTR => K::Io(IO::Interrupted),
38 E::EACCES => K::Io(IO::PermissionDenied),
39 E::ENOENT => K::Io(IO::NotFound),
40 _ => K::Unknown,
41 };
42 Error::new(kind, e.desc())
43 }
44}