error: implement default error traits

This commit is contained in:
meh 2016-04-30 22:54:13 +02:00
parent f9ff9117ac
commit b1576fd32d
1 changed files with 27 additions and 0 deletions

View File

@ -1,3 +1,5 @@
use std::fmt;
use std::error;
use std::ffi;
use nix;
@ -39,3 +41,28 @@ impl From<udev::Error> 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.",
}
}
}