From 53270c01e975a4fba56b61975a66eee24649e9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Tue, 26 Dec 2023 10:14:00 -0100 Subject: [PATCH] Hide GetConn This makes the future implementation private. This is a braking change, but: * It is unlikely anyone was using GetConn directly instead of just awaiting it. * This opens the way for replacing the manual implementation with an async fn. --- src/conn/pool/futures/get_conn.rs | 17 +++++++++++------ src/conn/pool/futures/mod.rs | 4 ++-- src/conn/pool/mod.rs | 8 ++++---- src/lib.rs | 2 +- tests/exports.rs | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/conn/pool/futures/get_conn.rs b/src/conn/pool/futures/get_conn.rs index b89f9bc6..0b5672b7 100644 --- a/src/conn/pool/futures/get_conn.rs +++ b/src/conn/pool/futures/get_conn.rs @@ -58,20 +58,25 @@ impl fmt::Debug for GetConnInner { /// This future will take connection from a pool and resolve to [`Conn`]. #[derive(Debug)] #[must_use = "futures do nothing unless you `.await` or poll them"] -pub struct GetConn { - pub(crate) queue_id: QueueId, - pub(crate) pool: Option, - pub(crate) inner: GetConnInner, +struct GetConn { + queue_id: QueueId, + pool: Option, + inner: GetConnInner, reset_upon_returning_to_a_pool: bool, #[cfg(feature = "tracing")] span: Arc, } +pub(crate) async fn get_conn(pool: Pool) -> Result { + let reset_connection = pool.opts.pool_opts().reset_connection(); + GetConn::new(pool, reset_connection).await +} + impl GetConn { - pub(crate) fn new(pool: &Pool, reset_upon_returning_to_a_pool: bool) -> GetConn { + fn new(pool: Pool, reset_upon_returning_to_a_pool: bool) -> GetConn { GetConn { queue_id: QueueId::next(), - pool: Some(pool.clone()), + pool: Some(pool), inner: GetConnInner::New, reset_upon_returning_to_a_pool, #[cfg(feature = "tracing")] diff --git a/src/conn/pool/futures/mod.rs b/src/conn/pool/futures/mod.rs index 00842994..6cf18080 100644 --- a/src/conn/pool/futures/mod.rs +++ b/src/conn/pool/futures/mod.rs @@ -6,8 +6,8 @@ // option. All files in the project carrying such notice may not be copied, // modified, or distributed except according to those terms. +pub use self::disconnect_pool::DisconnectPool; +pub(crate) use self::get_conn::get_conn; pub(super) use self::get_conn::GetConnInner; -pub use self::{disconnect_pool::DisconnectPool, get_conn::GetConn}; - mod disconnect_pool; mod get_conn; diff --git a/src/conn/pool/mod.rs b/src/conn/pool/mod.rs index 465ea8e4..a222da8a 100644 --- a/src/conn/pool/mod.rs +++ b/src/conn/pool/mod.rs @@ -15,6 +15,7 @@ use std::{ cmp::Reverse, collections::VecDeque, convert::TryFrom, + future::Future, hash::{Hash, Hasher}, str::FromStr, sync::{atomic, Arc, Mutex}, @@ -239,9 +240,8 @@ impl Pool { } /// Async function that resolves to `Conn`. - pub fn get_conn(&self) -> GetConn { - let reset_connection = self.opts.pool_opts().reset_connection(); - GetConn::new(self, reset_connection) + pub fn get_conn(&self) -> impl Future> { + get_conn(self.clone()) } /// Starts a new transaction. @@ -253,7 +253,7 @@ impl Pool { /// Async function that disconnects this pool from the server and resolves to `()`. /// /// **Note:** This Future won't resolve until all active connections, taken from it, - /// are dropped or disonnected. Also all pending and new `GetConn`'s will resolve to error. + /// are dropped or disonnected. Also all pending and new `get_conn()`'s will resolve to error. pub fn disconnect(self) -> DisconnectPool { DisconnectPool::new(self) } diff --git a/src/lib.rs b/src/lib.rs index af44f67f..e642287b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -542,7 +542,7 @@ pub use self::queryable::stmt::Statement; /// Futures used in this crate pub mod futures { - pub use crate::conn::pool::futures::{DisconnectPool, GetConn}; + pub use crate::conn::pool::futures::DisconnectPool; } /// Traits used in this crate diff --git a/tests/exports.rs b/tests/exports.rs index 6f9feef8..fb1fcd32 100644 --- a/tests/exports.rs +++ b/tests/exports.rs @@ -1,7 +1,7 @@ #[allow(unused_imports)] use mysql_async::{ consts, from_row, from_row_opt, from_value, from_value_opt, - futures::{DisconnectPool, GetConn}, + futures::DisconnectPool, params, prelude::{ BatchQuery, FromRow, FromValue, GlobalHandler, Protocol, Query, Queryable, StatementLike,