You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
1.7 KiB
Rust
101 lines
1.7 KiB
Rust
use std::fmt;
|
|
use std::error;
|
|
use std::ffi;
|
|
use std::io;
|
|
use std::sync::mpsc;
|
|
use nix;
|
|
|
|
#[cfg(feature = "udev")]
|
|
use udev;
|
|
|
|
use libc;
|
|
|
|
/// UInput error.
|
|
#[derive(Debug)]
|
|
pub enum Error {
|
|
/// System errors.
|
|
Nix(nix::Error),
|
|
|
|
/// Errors with internal nulls in names.
|
|
Nul(ffi::NulError),
|
|
|
|
#[cfg(feature = "udev")]
|
|
/// Errors coming from udev.
|
|
Udev(udev::Error),
|
|
|
|
Io(io::Error),
|
|
|
|
Send(mpsc::SendError<libc::input_event>),
|
|
|
|
/// The uinput file could not be found.
|
|
NotFound,
|
|
|
|
/// error reading input_event
|
|
ShortRead,
|
|
}
|
|
|
|
impl From<ffi::NulError> for Error {
|
|
fn from(value: ffi::NulError) -> Self {
|
|
Error::Nul(value)
|
|
}
|
|
}
|
|
|
|
impl From<nix::Error> for Error {
|
|
fn from(value: nix::Error) -> Self {
|
|
Error::Nix(value)
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "udev")]
|
|
impl From<udev::Error> for Error {
|
|
fn from(value: udev::Error) -> Self {
|
|
Error::Udev(value)
|
|
}
|
|
}
|
|
|
|
impl From<io::Error> for Error {
|
|
fn from(value: io::Error) -> Self {
|
|
Error::Io(value)
|
|
}
|
|
}
|
|
|
|
impl From<mpsc::SendError<libc::input_event>> for Error {
|
|
fn from(value: mpsc::SendError<libc::input_event>) -> Self {
|
|
Error::Send(value)
|
|
}
|
|
}
|
|
|
|
impl fmt::Display for Error {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
|
f.write_str(error::Error::description(self))
|
|
}
|
|
}
|
|
|
|
impl error::Error for Error {
|
|
fn description(&self) -> &str {
|
|
match self {
|
|
&Error::Nix(ref err) =>
|
|
err.description(),
|
|
|
|
&Error::Nul(ref err) =>
|
|
err.description(),
|
|
|
|
#[cfg(feature = "udev")]
|
|
&Error::Udev(ref err) =>
|
|
err.description(),
|
|
|
|
&Error::Io(ref err) =>
|
|
err.description(),
|
|
|
|
&Error::Send(ref err) =>
|
|
err.description(),
|
|
|
|
&Error::NotFound =>
|
|
"Device not found.",
|
|
|
|
&Error::ShortRead =>
|
|
"Error while reading from device file.",
|
|
}
|
|
}
|
|
}
|