From dd8d28bf5eebeecc839768d6f962f1acbbe52561 Mon Sep 17 00:00:00 2001 From: Gabriel Bastos Date: Fri, 6 Dec 2024 13:05:50 -0300 Subject: [PATCH 1/3] Bump MSRV to 1.75 --- .github/workflows/main.yml | 2 +- bb8/Cargo.toml | 2 +- postgres/Cargo.toml | 2 +- redis/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 27421c8..039c31b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,7 +36,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: 1.70.0 + toolchain: 1.75.0 - run: cargo test -p bb8 lint: diff --git a/bb8/Cargo.toml b/bb8/Cargo.toml index d952c99..1f0cfcb 100644 --- a/bb8/Cargo.toml +++ b/bb8/Cargo.toml @@ -2,7 +2,7 @@ name = "bb8" version = "0.8.6" edition = "2021" -rust-version = "1.70" +rust-version = "1.75" description = "Full-featured async (tokio-based) connection pool (like r2d2)" license = "MIT" repository = "https://github.com/djc/bb8" diff --git a/postgres/Cargo.toml b/postgres/Cargo.toml index 79bb758..9d79544 100644 --- a/postgres/Cargo.toml +++ b/postgres/Cargo.toml @@ -2,7 +2,7 @@ name = "bb8-postgres" version = "0.8.1" edition = "2021" -rust-version = "1.63" +rust-version = "1.75" description = "Full-featured async (tokio-based) postgres connection pool (like r2d2)" license = "MIT" repository = "https://github.com/djc/bb8" diff --git a/redis/Cargo.toml b/redis/Cargo.toml index 76e6586..403944f 100644 --- a/redis/Cargo.toml +++ b/redis/Cargo.toml @@ -2,7 +2,7 @@ name = "bb8-redis" version = "0.17.0" edition = "2021" -rust-version = "1.63" +rust-version = "1.75" description = "Full-featured async (tokio-based) redis connection pool (like r2d2)" license = "MIT" repository = "https://github.com/djc/bb8" From 4de4b139b9d5ef00a6e43a738a0cc8a8112d9e7d Mon Sep 17 00:00:00 2001 From: Gabriel Bastos Date: Fri, 6 Dec 2024 13:05:33 -0300 Subject: [PATCH 2/3] Replace async_trait with native async fns --- bb8/Cargo.toml | 1 - bb8/src/api.rs | 20 ++++++++++++-------- bb8/tests/test.rs | 21 ++++++++------------- postgres/Cargo.toml | 1 - postgres/examples/custom_state.rs | 26 +++++++++++++++----------- postgres/src/lib.rs | 2 -- redis/Cargo.toml | 1 - redis/src/lib.rs | 2 -- 8 files changed, 35 insertions(+), 39 deletions(-) diff --git a/bb8/Cargo.toml b/bb8/Cargo.toml index 1f0cfcb..c0a17af 100644 --- a/bb8/Cargo.toml +++ b/bb8/Cargo.toml @@ -10,7 +10,6 @@ workspace = ".." readme = "../README.md" [dependencies] -async-trait = "0.1" futures-util = { version = "0.3.2", default-features = false, features = ["alloc"] } parking_lot = { version = "0.12", optional = true } tokio = { version = "1.0", features = ["rt", "sync", "time"] } diff --git a/bb8/src/api.rs b/bb8/src/api.rs index ba43eea..3d64dcc 100644 --- a/bb8/src/api.rs +++ b/bb8/src/api.rs @@ -1,12 +1,12 @@ use std::borrow::Cow; use std::error; use std::fmt; +use std::future::Future; use std::marker::PhantomData; use std::ops::{Deref, DerefMut}; +use std::pin::Pin; use std::time::Duration; -use async_trait::async_trait; - use crate::inner::PoolInner; use crate::internals::Conn; @@ -381,7 +381,6 @@ impl Builder { } /// A trait which provides connection-specific functionality. -#[async_trait] pub trait ManageConnection: Sized + Send + Sync + 'static { /// The connection type this manager deals with. type Connection: Send + 'static; @@ -389,15 +388,17 @@ pub trait ManageConnection: Sized + Send + Sync + 'static { type Error: fmt::Debug + Send + 'static; /// Attempts to create a new connection. - async fn connect(&self) -> Result; + fn connect(&self) -> impl Future> + Send; /// Determines if the connection is still connected to the database. - async fn is_valid(&self, conn: &mut Self::Connection) -> Result<(), Self::Error>; + fn is_valid( + &self, + conn: &mut Self::Connection, + ) -> impl Future> + Send; /// Synchronously determine if the connection is no longer usable, if possible. fn has_broken(&self, conn: &mut Self::Connection) -> bool; } /// A trait which provides functionality to initialize a connection -#[async_trait] pub trait CustomizeConnection: fmt::Debug + Send + Sync + 'static { @@ -406,8 +407,11 @@ pub trait CustomizeConnection: /// /// The default implementation simply returns `Ok(())`. If this method returns an /// error, it will be forwarded to the configured error sink. - async fn on_acquire(&self, _connection: &mut C) -> Result<(), E> { - Ok(()) + fn on_acquire<'a>( + &'a self, + _connection: &'a mut C, + ) -> Pin> + Send + 'a>> { + Box::pin(async { Ok(()) }) } } diff --git a/bb8/tests/test.rs b/bb8/tests/test.rs index 8680309..2714023 100644 --- a/bb8/tests/test.rs +++ b/bb8/tests/test.rs @@ -9,7 +9,6 @@ use std::task::Poll; use std::time::Duration; use std::{error, fmt}; -use async_trait::async_trait; use futures_util::future::{err, lazy, ok, pending, ready, try_join_all, FutureExt}; use futures_util::stream::{FuturesUnordered, TryStreamExt}; use tokio::sync::oneshot; @@ -43,7 +42,6 @@ impl OkManager { } } -#[async_trait] impl ManageConnection for OkManager where C: Default + Send + Sync + 'static, @@ -78,7 +76,6 @@ impl NthConnectionFailManager { } } -#[async_trait] impl ManageConnection for NthConnectionFailManager where C: Default + Send + Sync + 'static, @@ -214,7 +211,6 @@ struct BrokenConnectionManager { _c: PhantomData, } -#[async_trait] impl ManageConnection for BrokenConnectionManager { type Connection = C; type Error = Error; @@ -380,7 +376,6 @@ async fn test_now_invalid() { struct Handler; - #[async_trait] impl ManageConnection for Handler { type Connection = FakeConnection; type Error = Error; @@ -689,7 +684,6 @@ async fn test_conns_drop_on_pool_drop() { struct Handler; - #[async_trait] impl ManageConnection for Handler { type Connection = Connection; type Error = Error; @@ -741,7 +735,6 @@ async fn test_retry() { struct Connection; struct Handler; - #[async_trait] impl ManageConnection for Handler { type Connection = Connection; type Error = Error; @@ -787,7 +780,6 @@ async fn test_conn_fail_once() { } } - #[async_trait] impl ManageConnection for Handler { type Connection = Connection; type Error = Error; @@ -912,11 +904,15 @@ async fn test_customize_connection_acquire() { count: AtomicUsize, } - #[async_trait] impl CustomizeConnection for CountingCustomizer { - async fn on_acquire(&self, connection: &mut Connection) -> Result<(), E> { - connection.custom_field = 1 + self.count.fetch_add(1, Ordering::SeqCst); - Ok(()) + fn on_acquire<'a>( + &'a self, + connection: &'a mut Connection, + ) -> Pin> + Send + 'a>> { + Box::pin(async move { + connection.custom_field = 1 + self.count.fetch_add(1, Ordering::SeqCst); + Ok(()) + }) } } @@ -952,7 +948,6 @@ async fn test_broken_connections_dont_starve_pool() { #[derive(Debug)] struct Connection; - #[async_trait::async_trait] impl bb8::ManageConnection for ConnectionManager { type Connection = Connection; type Error = Infallible; diff --git a/postgres/Cargo.toml b/postgres/Cargo.toml index 9d79544..ae78331 100644 --- a/postgres/Cargo.toml +++ b/postgres/Cargo.toml @@ -19,7 +19,6 @@ repository = "https://github.com/djc/bb8" "with-time-0_3" = ["tokio-postgres/with-time-0_3"] [dependencies] -async-trait = "0.1" bb8 = { version = "0.8", path = "../bb8" } tokio = { version = "1.0.0", features = ["rt"] } tokio-postgres = "0.7" diff --git a/postgres/examples/custom_state.rs b/postgres/examples/custom_state.rs index ec27f41..1bccdbc 100644 --- a/postgres/examples/custom_state.rs +++ b/postgres/examples/custom_state.rs @@ -1,8 +1,9 @@ use std::collections::BTreeMap; +use std::future::Future; use std::ops::Deref; +use std::pin::Pin; use std::str::FromStr; -use async_trait::async_trait; use bb8::{CustomizeConnection, Pool}; use bb8_postgres::PostgresConnectionManager; use tokio_postgres::config::Config; @@ -43,16 +44,20 @@ async fn main() { #[derive(Debug)] struct Customizer; -#[async_trait] impl CustomizeConnection for Customizer { - async fn on_acquire(&self, conn: &mut CustomPostgresConnection) -> Result<(), Error> { - conn.custom_state - .insert(QueryName::BasicSelect, conn.prepare("SELECT 1").await?); - - conn.custom_state - .insert(QueryName::Addition, conn.prepare("SELECT 1 + 1 + 1").await?); - - Ok(()) + fn on_acquire<'a>( + &'a self, + conn: &'a mut CustomPostgresConnection, + ) -> Pin> + Send + 'a>> { + Box::pin(async { + conn.custom_state + .insert(QueryName::BasicSelect, conn.prepare("SELECT 1").await?); + + conn.custom_state + .insert(QueryName::Addition, conn.prepare("SELECT 1 + 1 + 1").await?); + + Ok(()) + }) } } @@ -96,7 +101,6 @@ where } } -#[async_trait] impl bb8::ManageConnection for CustomPostgresConnectionManager where Tls: MakeTlsConnect + Clone + Send + Sync + 'static, diff --git a/postgres/src/lib.rs b/postgres/src/lib.rs index 3512d91..63f56cd 100644 --- a/postgres/src/lib.rs +++ b/postgres/src/lib.rs @@ -4,7 +4,6 @@ pub use bb8; pub use tokio_postgres; -use async_trait::async_trait; use tokio_postgres::config::Config; use tokio_postgres::tls::{MakeTlsConnect, TlsConnect}; use tokio_postgres::{Client, Error, Socket}; @@ -45,7 +44,6 @@ where } } -#[async_trait] impl bb8::ManageConnection for PostgresConnectionManager where Tls: MakeTlsConnect + Clone + Send + Sync + 'static, diff --git a/redis/Cargo.toml b/redis/Cargo.toml index 403944f..2b156ce 100644 --- a/redis/Cargo.toml +++ b/redis/Cargo.toml @@ -8,7 +8,6 @@ license = "MIT" repository = "https://github.com/djc/bb8" [dependencies] -async-trait = "0.1" bb8 = { version = "0.8", path = "../bb8" } redis = { version = "0.27", default-features = false, features = ["tokio-comp"] } diff --git a/redis/src/lib.rs b/redis/src/lib.rs index f62e9aa..1c65f2d 100644 --- a/redis/src/lib.rs +++ b/redis/src/lib.rs @@ -38,7 +38,6 @@ pub use bb8; pub use redis; -use async_trait::async_trait; use redis::{aio::MultiplexedConnection, ErrorKind}; use redis::{Client, IntoConnectionInfo, RedisError}; @@ -58,7 +57,6 @@ impl RedisConnectionManager { } } -#[async_trait] impl bb8::ManageConnection for RedisConnectionManager { type Connection = MultiplexedConnection; type Error = RedisError; From 8c104dd047b218882967917534b21fef920522da Mon Sep 17 00:00:00 2001 From: Gabriel Bastos Date: Fri, 6 Dec 2024 16:04:24 -0300 Subject: [PATCH 3/3] Major version bump for all crates --- bb8/Cargo.toml | 2 +- postgres/Cargo.toml | 4 ++-- redis/Cargo.toml | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bb8/Cargo.toml b/bb8/Cargo.toml index c0a17af..8e8bcdd 100644 --- a/bb8/Cargo.toml +++ b/bb8/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bb8" -version = "0.8.6" +version = "0.9.0" edition = "2021" rust-version = "1.75" description = "Full-featured async (tokio-based) connection pool (like r2d2)" diff --git a/postgres/Cargo.toml b/postgres/Cargo.toml index ae78331..b4abe57 100644 --- a/postgres/Cargo.toml +++ b/postgres/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bb8-postgres" -version = "0.8.1" +version = "0.9.0" edition = "2021" rust-version = "1.75" description = "Full-featured async (tokio-based) postgres connection pool (like r2d2)" @@ -19,7 +19,7 @@ repository = "https://github.com/djc/bb8" "with-time-0_3" = ["tokio-postgres/with-time-0_3"] [dependencies] -bb8 = { version = "0.8", path = "../bb8" } +bb8 = { version = "0.9", path = "../bb8" } tokio = { version = "1.0.0", features = ["rt"] } tokio-postgres = "0.7" diff --git a/redis/Cargo.toml b/redis/Cargo.toml index 2b156ce..9f5d351 100644 --- a/redis/Cargo.toml +++ b/redis/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bb8-redis" -version = "0.17.0" +version = "0.18.0" edition = "2021" rust-version = "1.75" description = "Full-featured async (tokio-based) redis connection pool (like r2d2)" @@ -8,7 +8,7 @@ license = "MIT" repository = "https://github.com/djc/bb8" [dependencies] -bb8 = { version = "0.8", path = "../bb8" } +bb8 = { version = "0.9", path = "../bb8" } redis = { version = "0.27", default-features = false, features = ["tokio-comp"] } [dev-dependencies]