Add error type

This commit is contained in:
Patrick Auernig 2018-03-29 22:57:00 +02:00
parent 332dbab413
commit 40be78dbd1
2 changed files with 34 additions and 0 deletions

33
src/error.rs Normal file
View File

@ -0,0 +1,33 @@
use std::error::Error as StdError;
use std::result::Result as StdResult;
use std::io::Error as IoError;
use std::fmt;
#[derive(Debug)]
pub enum Error {
Io(IoError),
Conversion,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(self.description())
}
}
impl StdError for Error {
fn description(&self) -> &str {
match *self {
Error::Conversion => "Failed to convert values",
Error::Io(ref err) => err.description()
}
}
}
impl From<IoError> for Error {
fn from(err: IoError) -> Self {
Error::Io(err)
}
}
pub type Result<T> = StdResult<T, Error>;

View File

@ -11,6 +11,7 @@ extern crate libc;
#[macro_use]
mod macros;
mod error;
mod utils;
mod connection;
mod models;