error.rs
899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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)
}
}