Skip to content

Commit 4e8f95d

Browse files
committed
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.
1 parent 8cda939 commit 4e8f95d

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

src/conn/pool/futures/get_conn.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,28 +57,33 @@ impl fmt::Debug for GetConnInner {
5757

5858
impl GetConnInner {
5959
/// Take the value of the inner connection, resetting it to `New`.
60-
pub fn take(&mut self) -> GetConnInner {
60+
fn take(&mut self) -> GetConnInner {
6161
std::mem::replace(self, GetConnInner::New)
6262
}
6363
}
6464

6565
/// This future will take connection from a pool and resolve to [`Conn`].
6666
#[derive(Debug)]
6767
#[must_use = "futures do nothing unless you `.await` or poll them"]
68-
pub struct GetConn {
69-
pub(crate) queue_id: QueueId,
70-
pub(crate) pool: Option<Pool>,
71-
pub(crate) inner: GetConnInner,
68+
struct GetConn {
69+
queue_id: QueueId,
70+
pool: Option<Pool>,
71+
inner: GetConnInner,
7272
reset_upon_returning_to_a_pool: bool,
7373
#[cfg(feature = "tracing")]
7474
span: Arc<Span>,
7575
}
7676

77+
pub(crate) async fn get_conn(pool: Pool) -> Result<Conn> {
78+
let reset_connection = pool.opts.pool_opts().reset_connection();
79+
GetConn::new(pool, reset_connection).await
80+
}
81+
7782
impl GetConn {
78-
pub(crate) fn new(pool: &Pool, reset_upon_returning_to_a_pool: bool) -> GetConn {
83+
fn new(pool: Pool, reset_upon_returning_to_a_pool: bool) -> GetConn {
7984
GetConn {
8085
queue_id: QueueId::next(),
81-
pool: Some(pool.clone()),
86+
pool: Some(pool),
8287
inner: GetConnInner::New,
8388
reset_upon_returning_to_a_pool,
8489
#[cfg(feature = "tracing")]

src/conn/pool/futures/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// option. All files in the project carrying such notice may not be copied,
77
// modified, or distributed except according to those terms.
88

9+
pub use self::disconnect_pool::DisconnectPool;
10+
pub(crate) use self::get_conn::get_conn;
911
pub(super) use self::get_conn::GetConnInner;
10-
pub use self::{disconnect_pool::DisconnectPool, get_conn::GetConn};
11-
1212
mod disconnect_pool;
1313
mod get_conn;

src/conn/pool/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::{
1515
cmp::Reverse,
1616
collections::VecDeque,
1717
convert::TryFrom,
18+
future::Future,
1819
hash::{Hash, Hasher},
1920
pin::Pin,
2021
str::FromStr,
@@ -228,9 +229,8 @@ impl Pool {
228229
}
229230

230231
/// Async function that resolves to `Conn`.
231-
pub fn get_conn(&self) -> GetConn {
232-
let reset_connection = self.opts.pool_opts().reset_connection();
233-
GetConn::new(self, reset_connection)
232+
pub fn get_conn(&self) -> impl Future<Output = Result<Conn>> {
233+
get_conn(self.clone())
234234
}
235235

236236
/// Starts a new transaction.
@@ -242,7 +242,7 @@ impl Pool {
242242
/// Async function that disconnects this pool from the server and resolves to `()`.
243243
///
244244
/// **Note:** This Future won't resolve until all active connections, taken from it,
245-
/// are dropped or disonnected. Also all pending and new `GetConn`'s will resolve to error.
245+
/// are dropped or disonnected. Also all pending and new `get_conn()`'s will resolve to error.
246246
pub fn disconnect(self) -> DisconnectPool {
247247
DisconnectPool::new(self)
248248
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ pub use self::queryable::stmt::Statement;
542542

543543
/// Futures used in this crate
544544
pub mod futures {
545-
pub use crate::conn::pool::futures::{DisconnectPool, GetConn};
545+
pub use crate::conn::pool::futures::DisconnectPool;
546546
}
547547

548548
/// Traits used in this crate

tests/exports.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[allow(unused_imports)]
22
use mysql_async::{
33
consts, from_row, from_row_opt, from_value, from_value_opt,
4-
futures::{DisconnectPool, GetConn},
4+
futures::DisconnectPool,
55
params,
66
prelude::{
77
BatchQuery, FromRow, FromValue, GlobalHandler, Protocol, Query, Queryable, StatementLike,

0 commit comments

Comments
 (0)