Skip to content

Commit

Permalink
updated pool wrappers; bumped to v0.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
yasamoka committed Apr 14, 2024
1 parent 2ca9cfd commit 06a3f73
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "db-pool"
version = "0.2.0"
version = "0.2.1"
edition = "2021"
description = "A thread-safe database pool for running database-tied integration tests in parallel"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions book/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion book/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "book"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
19 changes: 18 additions & 1 deletion src/async/wrapper.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use std::ops::Deref;

use super::{backend::r#trait::Backend, db_pool::ReusableConnectionPool};
use super::{
backend::r#trait::Backend, conn_pool::SingleUseConnectionPool, 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(B::Pool),
/// Reusable connection pool used in tests
ReusablePool(ReusableConnectionPool<'static, B>),
/// Single-use connection pool used in tests
SingleUsePool(SingleUseConnectionPool<B>),
}

impl<B: Backend> Deref for PoolWrapper<B> {
Expand All @@ -17,6 +21,19 @@ impl<B: Backend> Deref for PoolWrapper<B> {
match self {
Self::Pool(pool) => pool,
Self::ReusablePool(pool) => pool,
Self::SingleUsePool(pool) => pool,
}
}
}

impl<B: Backend> From<ReusableConnectionPool<'static, B>> for PoolWrapper<B> {
fn from(value: ReusableConnectionPool<'static, B>) -> Self {
Self::ReusablePool(value)
}
}

impl<B: Backend> From<SingleUseConnectionPool<B>> for PoolWrapper<B> {
fn from(value: SingleUseConnectionPool<B>) -> Self {
Self::SingleUsePool(value)
}
}
19 changes: 18 additions & 1 deletion src/sync/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ use std::ops::Deref;

use r2d2::Pool;

use super::{backend::r#trait::Backend, db_pool::ReusableConnectionPool};
use super::{
backend::r#trait::Backend, conn_pool::SingleUseConnectionPool, 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>),
/// Single-use connection pool used in tests
SingleUsePool(SingleUseConnectionPool<B>),
}

impl<B: Backend> Deref for PoolWrapper<B> {
Expand All @@ -19,6 +23,19 @@ impl<B: Backend> Deref for PoolWrapper<B> {
match self {
Self::Pool(pool) => pool,
Self::ReusablePool(pool) => pool,
Self::SingleUsePool(pool) => pool,
}
}
}

impl<B: Backend> From<ReusableConnectionPool<'static, B>> for PoolWrapper<B> {
fn from(value: ReusableConnectionPool<'static, B>) -> Self {
Self::ReusablePool(value)
}
}

impl<B: Backend> From<SingleUseConnectionPool<B>> for PoolWrapper<B> {
fn from(value: SingleUseConnectionPool<B>) -> Self {
Self::SingleUsePool(value)
}
}

0 comments on commit 06a3f73

Please sign in to comment.