db_pool/async/
wrapper.rs

1use std::ops::Deref;
2
3use super::{
4    backend::r#trait::Backend, conn_pool::SingleUseConnectionPool, db_pool::ReusableConnectionPool,
5};
6
7/// Connection pool wrapper to facilitate the use of pools in code under test and reusable pools in tests
8pub enum PoolWrapper<B: Backend> {
9    /// Connection pool used in code under test
10    Pool(B::Pool),
11    /// Reusable connection pool used in tests
12    ReusablePool(ReusableConnectionPool<'static, B>),
13    /// Single-use connection pool used in tests
14    SingleUsePool(SingleUseConnectionPool<B>),
15}
16
17impl<B: Backend> Deref for PoolWrapper<B> {
18    type Target = B::Pool;
19
20    fn deref(&self) -> &Self::Target {
21        match self {
22            Self::Pool(pool) => pool,
23            Self::ReusablePool(pool) => pool,
24            Self::SingleUsePool(pool) => pool,
25        }
26    }
27}
28
29impl<B: Backend> From<ReusableConnectionPool<'static, B>> for PoolWrapper<B> {
30    fn from(value: ReusableConnectionPool<'static, B>) -> Self {
31        Self::ReusablePool(value)
32    }
33}
34
35impl<B: Backend> From<SingleUseConnectionPool<B>> for PoolWrapper<B> {
36    fn from(value: SingleUseConnectionPool<B>) -> Self {
37        Self::SingleUsePool(value)
38    }
39}