1use crate::table::column::FromDataError;
2use crate::table::info::ValidateParamsError;
3
4use std::fmt;
5
6use tokio_postgres::error::Error as PostgresError;
7
8#[cfg(feature = "hash")]
9use bcrypt::BcryptError;
10
11#[derive(Debug)]
12pub enum Error {
13 Postgres(String),
14 FromData(FromDataError),
15 ValidateParamsError(ValidateParamsError),
16 #[cfg(feature = "hash")]
17 BcryptError(BcryptError),
18}
19
20impl fmt::Display for Error {
21 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22 fmt::Debug::fmt(self, f)
23 }
24}
25
26impl std::error::Error for Error {}
27
28impl From<PostgresError> for Error {
29 fn from(e: PostgresError) -> Self {
30 Self::Postgres(format!("{:?}", e))
31 }
32}
33
34impl From<FromDataError> for Error {
35 fn from(e: FromDataError) -> Self {
36 Self::FromData(e)
37 }
38}
39
40impl From<ValidateParamsError> for Error {
41 fn from(e: ValidateParamsError) -> Self {
42 Self::ValidateParamsError(e)
43 }
44}
45
46#[cfg(feature = "hash")]
47impl From<BcryptError> for Error {
48 fn from(e: BcryptError) -> Self {
49 Self::BcryptError(e)
50 }
51}