Skip to content

Commit

Permalink
Remove PoolInner::get_owned()
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Jan 29, 2024
1 parent a20c356 commit 0dca340
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 27 deletions.
17 changes: 6 additions & 11 deletions bb8/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ impl<M: ManageConnection> Pool<M> {
/// 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<PooledConnection<'static, M>, RunError<M::Error>> {
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.
Expand Down Expand Up @@ -385,17 +388,9 @@ where
pub(crate) fn drop_invalid(mut self) {
let _ = self.conn.take();
}
}

impl<M> PooledConnection<'static, M>
where
M: ManageConnection,
{
pub(crate) fn new_owned(pool: PoolInner<M>, conn: Conn<M::Connection>) -> Self {
Self {
pool: Cow::Owned(pool),
conn: Some(conn),
}
pub(crate) fn take(&mut self) -> Option<Conn<M::Connection>> {
self.conn.take()
}
}

Expand Down
16 changes: 0 additions & 16 deletions bb8/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,6 @@ where
}
}

pub(crate) async fn get_owned(
&self,
) -> Result<PooledConnection<'static, M>, RunError<M::Error>> {
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<M::Connection>) -> PooledConnection<'b, M>,
Expand Down

0 comments on commit 0dca340

Please sign in to comment.