Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide GetConn #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/conn/pool/futures/get_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pool>,
pub(crate) inner: GetConnInner,
struct GetConn {
queue_id: QueueId,
pool: Option<Pool>,
inner: GetConnInner,
reset_upon_returning_to_a_pool: bool,
#[cfg(feature = "tracing")]
span: Arc<Span>,
}

pub(crate) async fn get_conn(pool: Pool) -> Result<Conn> {
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")]
Expand Down
4 changes: 2 additions & 2 deletions src/conn/pool/futures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
8 changes: 4 additions & 4 deletions src/conn/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::{
borrow::Borrow,
cmp::Reverse,
collections::VecDeque,
future::Future,
hash::{Hash, Hasher},
str::FromStr,
sync::{atomic, Arc, Mutex},
Expand Down Expand Up @@ -238,9 +239,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<Output = Result<Conn>> {
get_conn(self.clone())
}

/// Starts a new transaction.
Expand All @@ -252,7 +252,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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,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
Expand Down
2 changes: 1 addition & 1 deletion tests/exports.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down