1use std::fmt;
2
3#[derive(Debug)]
7pub enum Error<A, B = A> {
8 Init(A),
10
11 Get(B),
13
14 Config(crate::figment::Error),
16}
17
18impl<A: fmt::Display, B: fmt::Display> fmt::Display for Error<A, B> {
19 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20 match self {
21 Error::Init(e) => write!(f, "failed to initialize database: {e}"),
22 Error::Get(e) => write!(f, "failed to get db connection: {e}"),
23 Error::Config(e) => write!(f, "bad configuration: {e}"),
24 }
25 }
26}
27
28impl<A, B> std::error::Error for Error<A, B>
29where
30 A: fmt::Debug + fmt::Display,
31 B: fmt::Debug + fmt::Display,
32{
33}
34
35impl<A, B> From<crate::figment::Error> for Error<A, B> {
36 fn from(e: crate::figment::Error) -> Self {
37 Self::Config(e)
38 }
39}