2016-04-30 16:54:13 -04:00
|
|
|
use std::fmt;
|
|
|
|
use std::error;
|
2016-04-24 22:32:24 -04:00
|
|
|
use std::ffi;
|
2017-11-15 00:03:42 -05:00
|
|
|
use std::io;
|
2017-11-16 00:13:46 -05:00
|
|
|
use std::sync::mpsc;
|
2016-04-24 22:32:24 -04:00
|
|
|
use nix;
|
|
|
|
|
2017-11-16 00:13:46 -05:00
|
|
|
use libc;
|
|
|
|
|
2016-04-25 11:57:45 -04:00
|
|
|
/// UInput error.
|
2016-04-24 22:32:24 -04:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2016-04-25 11:57:45 -04:00
|
|
|
/// System errors.
|
2016-04-24 22:32:24 -04:00
|
|
|
Nix(nix::Error),
|
2016-04-25 11:57:45 -04:00
|
|
|
|
|
|
|
/// Errors with internal nulls in names.
|
2016-04-24 22:32:24 -04:00
|
|
|
Nul(ffi::NulError),
|
|
|
|
|
2017-11-15 00:03:42 -05:00
|
|
|
Io(io::Error),
|
|
|
|
|
2017-11-16 00:13:46 -05:00
|
|
|
Send(mpsc::SendError<libc::input_event>),
|
|
|
|
|
2016-04-25 11:57:45 -04:00
|
|
|
/// The uinput file could not be found.
|
2016-04-24 22:32:24 -04:00
|
|
|
NotFound,
|
2017-11-15 00:03:42 -05:00
|
|
|
|
|
|
|
/// error reading input_event
|
|
|
|
ShortRead,
|
2016-04-24 22:32:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-15 00:03:42 -05:00
|
|
|
impl From<io::Error> for Error {
|
|
|
|
fn from(value: io::Error) -> Self {
|
|
|
|
Error::Io(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-16 00:13:46 -05:00
|
|
|
impl From<mpsc::SendError<libc::input_event>> for Error {
|
|
|
|
fn from(value: mpsc::SendError<libc::input_event>) -> Self {
|
|
|
|
Error::Send(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-30 16:54:13 -04:00
|
|
|
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(),
|
|
|
|
|
2017-11-15 00:03:42 -05:00
|
|
|
&Error::Io(ref err) =>
|
|
|
|
err.description(),
|
|
|
|
|
2017-11-16 00:13:46 -05:00
|
|
|
&Error::Send(ref err) =>
|
|
|
|
err.description(),
|
|
|
|
|
2016-04-30 16:54:13 -04:00
|
|
|
&Error::NotFound =>
|
|
|
|
"Device not found.",
|
2017-11-15 00:03:42 -05:00
|
|
|
|
|
|
|
&Error::ShortRead =>
|
|
|
|
"Error while reading from device file.",
|
2016-04-30 16:54:13 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|