Skip to main content

denise_evdev/
error.rs

1//! Failures from the evdev backend.
2
3use std::fmt;
4use std::io;
5use std::path::PathBuf;
6
7/// Something went wrong reading input devices.
8#[derive(Debug)]
9#[non_exhaustive]
10pub enum EvdevError {
11    /// `/dev/input` could not be listed.
12    Enumerate(io::Error),
13
14    /// A device node could not be opened.
15    ///
16    /// Almost always a permission problem: reading `/dev/input/event*` needs the
17    /// `input` group.
18    Open {
19        /// The device that failed.
20        path: PathBuf,
21        /// The underlying failure.
22        source: io::Error,
23    },
24
25    /// No device that this backend can use was found.
26    NoDevices,
27}
28
29impl fmt::Display for EvdevError {
30    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31        match self {
32            Self::Enumerate(_) => f.write_str("listing input devices"),
33            Self::Open { path, .. } => write!(f, "opening {}", path.display()),
34            Self::NoDevices => f.write_str("no usable pointer, touch or keyboard device found"),
35        }
36    }
37}
38
39impl std::error::Error for EvdevError {
40    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
41        match self {
42            Self::Enumerate(source) | Self::Open { source, .. } => Some(source),
43            Self::NoDevices => None,
44        }
45    }
46}