error.rs 899 Bytes
use std::error::Error as StdError;
use std::fmt;

use diesel::result;
use r2d2;

#[derive(Debug)]
pub(crate) enum Error {
    DieselResult(result::Error),
    DieselR2d2(r2d2::Error),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Error::DieselR2d2(r)   => write!(f, "{}", r),
            Error::DieselResult(r) => write!(f, "{}", r),
        }
    }
}

impl StdError for Error {
    fn source(&self) -> Option<&(dyn StdError + 'static)> {
        match self {
            Error::DieselR2d2(r)   => Some(r),
            Error::DieselResult(r) => Some(r),
        }
    }
}

impl From<result::Error> for Error {
    fn from(error: result::Error) -> Self {
        Error::DieselResult(error)
    }
}

impl From<r2d2::Error> for Error {
    fn from(error: r2d2::Error) -> Self {
        Error::DieselR2d2(error)
    }
}