@@ -87,7 +87,7 @@ impl CheckModeAtomic {
8787/// Connection wrapper with creation timestamp for lifetime tracking
8888pub struct DurationConnection < T > {
8989 inner : T ,
90- instant : Instant ,
90+ instant : Option < Instant > ,
9191}
9292
9393impl < T > Deref for DurationConnection < T > {
@@ -156,7 +156,13 @@ impl<M: Manager> Manager for DurationManager<M> {
156156 async fn connect ( & self ) -> Result < Self :: Connection , Self :: Error > {
157157 Ok ( DurationConnection {
158158 inner : self . manager . connect ( ) . await ?,
159- instant : Instant :: now ( ) ,
159+ instant : {
160+ match self . mode . get_mode ( ) {
161+ CheckMode :: NoLimit => None ,
162+ CheckMode :: SkipInterval ( _) => Some ( Instant :: now ( ) ) ,
163+ CheckMode :: MaxLifetime ( _) => Some ( Instant :: now ( ) ) ,
164+ }
165+ } ,
160166 } )
161167 }
162168
@@ -168,17 +174,35 @@ impl<M: Manager> Manager for DurationManager<M> {
168174 }
169175 CheckMode :: SkipInterval ( duration) => {
170176 // Skip if within check interval
171- if conn. instant . elapsed ( ) < * duration {
172- return Ok ( ( ) ) ;
177+ if let Some ( instant) = conn. instant . as_ref ( ) {
178+ if instant. elapsed ( ) < * duration {
179+ return Ok ( ( ) ) ;
180+ }
173181 }
174182 }
175- CheckMode :: MaxLifetime ( max_lifetime ) => {
183+ CheckMode :: MaxLifetime ( duration ) => {
176184 // Fail if connection exceeded max lifetime
177- if conn. instant . elapsed ( ) > * max_lifetime {
178- return Err ( M :: Error :: from ( "connection exceeded max lifetime" ) ) ;
185+ if let Some ( instant) = conn. instant . as_ref ( ) {
186+ if instant. elapsed ( ) > * duration {
187+ return Err ( M :: Error :: from ( "connection exceeded max lifetime" ) ) ;
188+ }
179189 }
180190 }
181191 }
182192 self . manager . check ( conn) . await
183193 }
184194}
195+
196+
197+ impl < M : Manager > Deref for DurationManager < M > {
198+ type Target = M ;
199+ fn deref ( & self ) -> & Self :: Target {
200+ & self . manager
201+ }
202+ }
203+
204+ impl < M : Manager > DerefMut for DurationManager < M > {
205+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
206+ & mut self . manager
207+ }
208+ }
0 commit comments