1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use std::ops::Deref;

use r2d2::Pool;

use super::{backend::r#trait::Backend, db_pool::ReusableConnectionPool};

/// Connection pool wrapper to facilitate the use of pools in code under test and reusable pools in tests
pub enum PoolWrapper<B: Backend> {
    /// Connection pool used in code under test
    Pool(Pool<B::ConnectionManager>),
    /// Reusable connection pool used in tests
    ReusablePool(ReusableConnectionPool<'static, B>),
}

impl<B: Backend> Deref for PoolWrapper<B> {
    type Target = Pool<B::ConnectionManager>;

    fn deref(&self) -> &Self::Target {
        match self {
            Self::Pool(pool) => pool,
            Self::ReusablePool(pool) => pool,
        }
    }
}