1use std::ops::Deref;
2
3use r2d2::Pool;
4
5use super::{
6 backend::r#trait::Backend, conn_pool::SingleUseConnectionPool, db_pool::ReusableConnectionPool,
7};
8
9pub enum PoolWrapper<B: Backend> {
11 Pool(Pool<B::ConnectionManager>),
13 ReusablePool(ReusableConnectionPool<'static, B>),
15 SingleUsePool(SingleUseConnectionPool<B>),
17}
18
19impl<B: Backend> Deref for PoolWrapper<B> {
20 type Target = Pool<B::ConnectionManager>;
21
22 fn deref(&self) -> &Self::Target {
23 match self {
24 Self::Pool(pool) => pool,
25 Self::ReusablePool(pool) => pool,
26 Self::SingleUsePool(pool) => pool,
27 }
28 }
29}
30
31impl<B: Backend> From<ReusableConnectionPool<'static, B>> for PoolWrapper<B> {
32 fn from(value: ReusableConnectionPool<'static, B>) -> Self {
33 Self::ReusablePool(value)
34 }
35}
36
37impl<B: Backend> From<SingleUseConnectionPool<B>> for PoolWrapper<B> {
38 fn from(value: SingleUseConnectionPool<B>) -> Self {
39 Self::SingleUsePool(value)
40 }
41}