use nix;
use std::ffi;
use std::fmt;
#[cfg(feature = "udev")]
use udev;
#[derive(Debug)]
pub enum Error {
Nix(nix::Error),
Nul(ffi::NulError),
#[cfg(feature = "udev")]
Udev(udev::Error),
IoError(std::io::Error),
NotFound,
}
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 fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
let message = match self {
Error::Nix(e) => e.to_string(),
Error::Nul(e) => e.to_string(),
#[cfg(feature = "udev")]
Error::Udev(e) => e.to_string(),
Error::IoError(e) => e.to_string(),
Error::NotFound => "Device not found.".to_string(),
};
f.write_str(&message)
}
}
impl std::error::Error for Error {}