You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.4 KiB

use std::fmt;
use std::error;
6 years ago
use std::ffi;
use std::io;
3 years ago
#[cfg(target_os = "linux")]
6 years ago
use nix;
6 years ago
/// UInput error.
6 years ago
#[derive(Debug)]
pub enum Error {
6 years ago
/// System errors.
3 years ago
#[cfg(target_os = "linux")]
6 years ago
Nix(nix::Error),
6 years ago
/// Errors with internal nulls in names.
6 years ago
Nul(ffi::NulError),
Io(io::Error),
#[cfg(feature = "toml_serde")]
Toml(toml::de::Error),
NotAKeyboard,
/// error reading input_event
ShortRead,
/// epoll already added
EpollAlreadyAdded,
6 years ago
}
impl From<ffi::NulError> for Error {
fn from(value: ffi::NulError) -> Self {
Error::Nul(value)
}
}
3 years ago
#[cfg(target_os = "linux")]
6 years ago
impl From<nix::Error> for Error {
fn from(value: nix::Error) -> Self {
Error::Nix(value)
}
}
impl From<io::Error> for Error {
fn from(value: io::Error) -> Self {
Error::Io(value)
}
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match self {
3 years ago
#[cfg(target_os = "linux")]
&Error::Nix(ref err) => err.fmt(f),
&Error::Nul(ref err) => err.fmt(f),
&Error::Io(ref err) => err.fmt(f),
#[cfg(feature = "toml_serde")]
&Error::Toml(ref err) => err.fmt(f),
&Error::NotAKeyboard => f.write_str("This device file is not a keyboard"),
&Error::ShortRead => f.write_str("Error while reading from device file."),
&Error::EpollAlreadyAdded => f.write_str("epoll already added, delete first"),
}
}
}
impl error::Error for Error {}