diff --git a/src/error.rs b/src/error.rs index 09d5eae..f1d4be4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,3 +1,5 @@ +use std::fmt; +use std::error; use std::ffi; use nix; @@ -39,3 +41,28 @@ impl From for Error { Error::Udev(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::NotFound => + "Device not found.", + } + } +}