2021-03-12 23:44:19 +00:00
|
|
|
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.
|
2021-03-20 01:09:13 +00:00
|
|
|
///
|
|
|
|
/// [`Poolable`]: crate::databases::Poolable
|
2021-03-12 23:44:19 +00:00
|
|
|
#[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)
|
|
|
|
}
|
|
|
|
}
|