error: implement default error traits
This commit is contained in:
parent
f9ff9117ac
commit
b1576fd32d
27
src/error.rs
27
src/error.rs
@ -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.",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user