diff --git a/bb8/src/api.rs b/bb8/src/api.rs index 548fd04..9ecad68 100644 --- a/bb8/src/api.rs +++ b/bb8/src/api.rs @@ -60,7 +60,10 @@ impl Pool { /// Using an owning `PooledConnection` makes it easier to leak the connection pool. Therefore, [`Pool::get`] /// (which stores a lifetime-bound reference to the pool) should be preferred whenever possible. pub async fn get_owned(&self) -> Result, RunError> { - self.inner.get_owned().await + Ok(PooledConnection { + conn: self.get().await?.take(), + pool: Cow::Owned(self.inner.clone()), + }) } /// Get a new dedicated connection that will not be managed by the pool. @@ -385,17 +388,9 @@ where pub(crate) fn drop_invalid(mut self) { let _ = self.conn.take(); } -} -impl PooledConnection<'static, M> -where - M: ManageConnection, -{ - pub(crate) fn new_owned(pool: PoolInner, conn: Conn) -> Self { - Self { - pool: Cow::Owned(pool), - conn: Some(conn), - } + pub(crate) fn take(&mut self) -> Option> { + self.conn.take() } } diff --git a/bb8/src/inner.rs b/bb8/src/inner.rs index 5842324..0c3bbb6 100644 --- a/bb8/src/inner.rs +++ b/bb8/src/inner.rs @@ -89,22 +89,6 @@ where } } - pub(crate) async fn get_owned( - &self, - ) -> Result, RunError> { - let future = self.make_pooled(|this, conn| { - let pool = PoolInner { - inner: Arc::clone(&this.inner), - }; - PooledConnection::new_owned(pool, conn) - }); - - match timeout(self.inner.statics.connection_timeout, future).await { - Ok(result) => result, - _ => Err(RunError::TimedOut), - } - } - pub(crate) async fn make_pooled<'a, 'b>( &'a self, make_pooled_conn: impl Fn(&'a Self, Conn) -> PooledConnection<'b, M>,