Skip to content

Commit 3b6de61

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 125aebe commit 3b6de61

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

src/conn/pool/futures/get_conn.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,25 @@ impl fmt::Debug for GetConnInner {
5858
/// This future will take connection from a pool and resolve to [`Conn`].
5959
#[derive(Debug)]
6060
#[must_use = "futures do nothing unless you `.await` or poll them"]
61-
pub struct GetConn {
62-
pub(crate) queue_id: QueueId,
63-
pub(crate) pool: Option<Pool>,
64-
pub(crate) inner: GetConnInner,
61+
struct GetConn {
62+
queue_id: QueueId,
63+
pool: Option<Pool>,
64+
inner: GetConnInner,
6565
reset_upon_returning_to_a_pool: bool,
6666
#[cfg(feature = "tracing")]
6767
span: Arc<Span>,
6868
}
6969

70+
pub(crate) async fn get_conn(pool: Pool) -> Result<Conn> {
71+
let reset_connection = pool.opts.pool_opts().reset_connection();
72+
GetConn::new(pool, reset_connection).await
73+
}
74+
7075
impl GetConn {
71-
pub(crate) fn new(pool: &Pool, reset_upon_returning_to_a_pool: bool) -> GetConn {
76+
fn new(pool: Pool, reset_upon_returning_to_a_pool: bool) -> GetConn {
7277
GetConn {
7378
queue_id: QueueId::next(),
74-
pool: Some(pool.clone()),
79+
pool: Some(pool),
7580
inner: GetConnInner::New,
7681
reset_upon_returning_to_a_pool,
7782
#[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
@@ -14,6 +14,7 @@ use std::{
1414
borrow::Borrow,
1515
cmp::Reverse,
1616
collections::VecDeque,
17+
future::Future,
1718
hash::{Hash, Hasher},
1819
str::FromStr,
1920
sync::{atomic, Arc, Mutex},
@@ -238,9 +239,8 @@ impl Pool {
238239
}
239240

240241
/// Async function that resolves to `Conn`.
241-
pub fn get_conn(&self) -> GetConn {
242-
let reset_connection = self.opts.pool_opts().reset_connection();
243-
GetConn::new(self, reset_connection)
242+
pub fn get_conn(&self) -> impl Future<Output = Result<Conn>> {
243+
get_conn(self.clone())
244244
}
245245

246246
/// Starts a new transaction.
@@ -252,7 +252,7 @@ impl Pool {
252252
/// Async function that disconnects this pool from the server and resolves to `()`.
253253
///
254254
/// **Note:** This Future won't resolve until all active connections, taken from it,
255-
/// are dropped or disonnected. Also all pending and new `GetConn`'s will resolve to error.
255+
/// are dropped or disonnected. Also all pending and new `get_conn()`'s will resolve to error.
256256
pub fn disconnect(self) -> DisconnectPool {
257257
DisconnectPool::new(self)
258258
}

src/lib.rs

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

552552
/// Futures used in this crate
553553
pub mod futures {
554-
pub use crate::conn::pool::futures::{DisconnectPool, GetConn};
554+
pub use crate::conn::pool::futures::DisconnectPool;
555555
}
556556

557557
/// 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)