diff options
Diffstat (limited to 'src/error.rs')
-rw-r--r-- | src/error.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs new file mode 100644 index 0000000..6ab0741 --- /dev/null +++ b/src/error.rs @@ -0,0 +1,36 @@ +use std::convert::From; +use std::error::Error as StdError; +use bcrypt::BcryptError; +use diesel::result::Error as DieselErr; +use std::fmt; + +#[derive(Debug)] +pub enum Error { + DieselError(DieselErr), + PasswordError(BcryptError), + AlreadyExists, +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + Error::DieselError(ref e) => e.fmt(f), + Error::PasswordError(ref e) => e.fmt(f), + Error::AlreadyExists => f.write_str("AlreadyExists"), + } + } +} + +impl From<DieselErr> for Error { + fn from(e: DieselErr) -> Error { + Error::DieselError(e) + } +} + +impl From<BcryptError> for Error { + fn from(e: BcryptError) -> Error { + Error::PasswordError(e) + } +} + +impl StdError for Error {} |