pub struct PooledConnection { /* private fields */ }Expand description
连接池中的连接条目,记录创建时间和最后使用时间
created_at:连接的原始创建时间,不随 acquire/release 重置, 用于max_lifetime过期判定。last_used_at:上次归还到池的时间,用于idle_timeout空闲超时判定。pool:归属的连接池引用,Drop 时自动归还。None表示无需归还 (已通过release()/into_inner()显式处理)。
Implementations§
Source§impl PooledConnection
impl PooledConnection
Sourcepub fn created_at(&self) -> Instant
pub fn created_at(&self) -> Instant
连接的原始创建时间(不随 acquire/release 重置)
Sourcepub fn into_inner(self) -> Box<dyn Connection>
pub fn into_inner(self) -> Box<dyn Connection>
提取内部连接(消费 PooledConnection)
用于将连接传递给 Transaction::new 等消费连接的 API。
调用此方法后,连接不再属于池,调用方需自行管理其生命周期。
Trait Implementations§
Source§impl Deref for PooledConnection
impl Deref for PooledConnection
Source§type Target = dyn Connection
type Target = dyn Connection
The resulting type after dereferencing.
Source§impl DerefMut for PooledConnection
impl DerefMut for PooledConnection
Source§impl Drop for PooledConnection
PooledConnection 的 Drop 实现:自动归还连接到池中
impl Drop for PooledConnection
PooledConnection 的 Drop 实现:自动归还连接到池中
修复 Critical Bug:之前 PooledConnection 未实现 Drop,连接在 drop 时 丢失,不归还池中,导致池耗尽。
实现策略:
- 如果
pool为Some(未显式 release/into_inner),取出连接并放入ClosedConnection占位符 - 在 tokio runtime 中 spawn 异步 release(Drop 不能 await)
- 如果不在 tokio runtime 中(P0 修复):手动递减
total_count, 避免池容量被耗尽;连接随pooleddrop 自然释放(依赖底层连接 Drop)
Auto Trait Implementations§
impl !RefUnwindSafe for PooledConnection
impl !UnwindSafe for PooledConnection
impl Freeze for PooledConnection
impl Send for PooledConnection
impl Sync for PooledConnection
impl Unpin for PooledConnection
impl UnsafeUnpin for PooledConnection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more