diff options
Diffstat (limited to 'nitrocli/src/error.rs')
-rw-r--r-- | nitrocli/src/error.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/nitrocli/src/error.rs b/nitrocli/src/error.rs index 65992f0..a88b5a7 100644 --- a/nitrocli/src/error.rs +++ b/nitrocli/src/error.rs @@ -19,11 +19,15 @@ use libhid; use std::fmt; +use std::io; +use std::string; #[derive(Debug)] pub enum Error { HidError(libhid::Error), + IoError(io::Error), + Utf8Error(string::FromUtf8Error), Error(String), } @@ -35,10 +39,26 @@ impl From<libhid::Error> for Error { } +impl From<io::Error> for Error { + fn from(e: io::Error) -> Error { + return Error::IoError(e); + } +} + + +impl From<string::FromUtf8Error> for Error { + fn from(e: string::FromUtf8Error) -> Error { + return Error::Utf8Error(e); + } +} + + impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *&self { &Error::HidError(ref e) => return write!(f, "hidapi error: {}", e), + &Error::Utf8Error(_) => return write!(f, "Encountered UTF-8 conversion error"), + &Error::IoError(ref e) => return write!(f, "IO error: {}", e.get_ref().unwrap()), &Error::Error(ref e) => return write!(f, "{}", e), } } |