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
use rocket::figment;

/// A wrapper around `r2d2::Error`s or a custom database error type.
///
/// This type is only relevant to implementors of the [`Poolable`] trait. See
/// the [`Poolable`] documentation for more information on how to use this type.
///
/// [`Poolable`]: crate::Poolable
#[derive(Debug)]
pub enum Error<T> {
    /// A custom error of type `T`.
    Custom(T),
    /// An error occurred while initializing an `r2d2` pool.
    Pool(r2d2::Error),
    /// An error occurred while extracting a `figment` configuration.
    Config(figment::Error),
}

impl<T> From<figment::Error> for Error<T> {
    fn from(error: figment::Error) -> Self {
        Error::Config(error)
    }
}

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