Debian Codegraph @

src/pool/connection.rs

raw symbols SCIP
1 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::{selfrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#};
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#};
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::{Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#, Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#};
5
6 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::syncrust-analyzer cargo sqlx-core 0.8.3 sync/::AsyncSemaphoreReleaserrust-analyzer cargo sqlx-core 0.8.3 sync/AsyncSemaphoreReleaser#;
7
8 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::connectionrust-analyzer cargo sqlx-core 0.8.3 connection/::Connectionrust-analyzer cargo sqlx-core 0.8.3 connection/Connection#;
9 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::databaserust-analyzer cargo sqlx-core 0.8.3 database/::Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#;
10 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::errorrust-analyzer cargo sqlx-core 0.8.3 error/::Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#;
11
12 use superrust-analyzer cargo sqlx-core 0.8.3 pool/::innerrust-analyzer cargo sqlx-core 0.8.3 pool/inner/::{is_beyond_max_lifetimerust-analyzer cargo sqlx-core 0.8.3 pool/inner/is_beyond_max_lifetime()., DecrementSizeGuardrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#, PoolInnerrust-analyzer cargo sqlx-core 0.8.3 pool/inner/PoolInner#};
13 use craterust-analyzer cargo sqlx-core 0.8.3 crate/::poolrust-analyzer cargo sqlx-core 0.8.3 pool/::optionsrust-analyzer cargo sqlx-core 0.8.3 pool/options/::PoolConnectionMetadatarust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolConnectionMetadata#;
14 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/::Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#;
15
16 const CLOSE_ON_DROP_TIMEOUTrust-analyzer cargo sqlx-core 0.8.3 pool/connection/CLOSE_ON_DROP_TIMEOUT.: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration# = Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(5);
17
18 /// A connection managed by a [`Pool`][crate::pool::Pool].
19 ///
20 /// Will be returned to the pool on-drop.
21 pub struct PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> {
22 liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#live.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#<DB>>,
23 close_on_droprust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#close_on_drop.: bool,
24 pub(craterust-analyzer cargo sqlx-core 0.8.3 crate/) poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#pool.: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<PoolInnerrust-analyzer cargo sqlx-core 0.8.3 pool/inner/PoolInner#<DB>>,
25 }
26
27 pub(superrust-analyzer cargo sqlx-core 0.8.3 pool/) struct Liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> {
28 pub(superrust-analyzer cargo sqlx-core 0.8.3 pool/) rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw.: DB::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection#,
29 pub(superrust-analyzer cargo sqlx-core 0.8.3 pool/) created_atrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#created_at.: Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#,
30 }
31
32 pub(superrust-analyzer cargo sqlx-core 0.8.3 pool/) struct Idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> {
33 pub(superrust-analyzer cargo sqlx-core 0.8.3 pool/) liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#live.: Liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#<DB>,
34 pub(superrust-analyzer cargo sqlx-core 0.8.3 pool/) idle_sincerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#idle_since.: Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#,
35 }
36
37 /// RAII wrapper for connections being handled by functions that may drop them
38 pub(superrust-analyzer cargo sqlx-core 0.8.3 pool/) struct Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#, C> {
39 pub(superrust-analyzer cargo sqlx-core 0.8.3 pool/) innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner.: C,
40 pub(superrust-analyzer cargo sqlx-core 0.8.3 pool/) guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard.: DecrementSizeGuardrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#<DB>,
41 }
42
43 const EXPECT_MSGrust-analyzer cargo sqlx-core 0.8.3 pool/connection/EXPECT_MSG.: &str = "BUG: inner connection already taken!";
44
45 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#<DB> {
46 fn fmtrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][Debug]fmt().(&self, f: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
47 // TODO: Show the type name of the connection ?
48 f.debug_structrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]debug_struct().("PoolConnection").finishrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/builders/impl#[`DebugStruct<'a, 'b>`]finish().()
49 }
50 }
51
52 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#<DB> {
53 type Targetrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][Deref]Target# = DB::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection#;
54
55 fn derefrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][Deref]deref().(&self) -> &Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][Deref]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
56 &self.liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#live..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().(EXPECT_MSGrust-analyzer cargo sqlx-core 0.8.3 pool/connection/EXPECT_MSG.).rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw.
57 }
58 }
59
60 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#<DB> {
61 fn deref_mutrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][DerefMut]deref_mut().(&mut self) -> &mut Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][DerefMut]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
62 &mut self.liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#live..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().(EXPECT_MSGrust-analyzer cargo sqlx-core 0.8.3 pool/connection/EXPECT_MSG.).rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw.
63 }
64 }
65
66 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<DB::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection#> for PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#<DB> {
67 fn as_refrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][`AsRef<<DB as Database>::Connection>`]as_ref().(&self) -> &DB::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection# {
68 self
69 }
70 }
71
72 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> AsMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#<DB::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection#> for PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#<DB> {
73 fn as_mutrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][`AsMut<<DB as Database>::Connection>`]as_mut().(&mut self) -> &mut DB::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection# {
74 self
75 }
76 }
77
78 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#<DB> {
79 /// Close this connection, allowing the pool to open a replacement.
80 ///
81 /// Equivalent to calling [`.detach()`] then [`.close()`], but the connection permit is retained
82 /// for the duration so that the pool may not exceed `max_connections`.
83 ///
84 /// [`.detach()`]: PoolConnection::detach
85 /// [`.close()`]: Connection::close
86 pub async fn closerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]close().(mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
87 let floating = self.take_liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]take_live().().floatrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Live<DB>`]float().(self.poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#pool..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().());
88 floating.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner..rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw..closerust-analyzer cargo sqlx-core 0.8.3 connection/Connection#close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().
89 }
90
91 /// Close this connection on-drop, instead of returning it to the pool.
92 ///
93 /// May be used in cases where waiting for the [`.close()`][Self::close] call
94 /// to complete is unacceptable, but you still want the connection to be closed gracefully
95 /// so that the server can clean up resources.
96 #[inline(always)]
97 pub fn close_on_droprust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]close_on_drop().(&mut self) {
98 self.close_on_droprust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#close_on_drop. = true;
99 }
100
101 /// Detach this connection from the pool, allowing it to open a replacement.
102 ///
103 /// Note that if your application uses a single shared pool, this
104 /// effectively lets the application exceed the [`max_connections`] setting.
105 ///
106 /// If [`min_connections`] is nonzero, a task will be spawned to replace this connection.
107 ///
108 /// If you want the pool to treat this connection as permanently checked-out,
109 /// use [`.leak()`][Self::leak] instead.
110 ///
111 /// [`max_connections`]: crate::pool::PoolOptions::max_connections
112 /// [`min_connections`]: crate::pool::PoolOptions::min_connections
113 pub fn detachrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]detach().(mut self) -> DB::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection# {
114 self.take_liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]take_live().().floatrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Live<DB>`]float().(self.poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#pool..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().()).detachrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]detach().()
115 }
116
117 /// Detach this connection from the pool, treating it as permanently checked-out.
118 ///
119 /// This effectively will reduce the maximum capacity of the pool by 1 every time it is used.
120 ///
121 /// If you don't want to impact the pool's capacity, use [`.detach()`][Self::detach] instead.
122 pub fn leakrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]leak().(mut self) -> DB::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection# {
123 self.take_liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]take_live().().rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw.
124 }
125
126 fn take_liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]take_live().(&mut self) -> Liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#<DB> {
127 self.liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#live..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().(EXPECT_MSGrust-analyzer cargo sqlx-core 0.8.3 pool/connection/EXPECT_MSG.)
128 }
129
130 /// Test the connection to make sure it is still live before returning it to the pool.
131 ///
132 /// This effectively runs the drop handler eagerly instead of spawning a task to do it.
133 #[doc(hidden)]
134 pub fn return_to_poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]return_to_pool().(&mut self) -> impl Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = ()> + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + 'static {
135 // float the connection in the pool before we move into the task
136 // in case the returned `Future` isn't executed, like if it's spawned into a dying runtime
137 // https://github.com/launchbadge/sqlx/issues/1396
138 // Type hints seem to be broken by `Option` combinators in IntelliJ Rust right now (6/22).
139 let floating: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#<DB, Liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#<DB>>> =
140 self.liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#live..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|live| live.floatrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Live<DB>`]float().(self.poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#pool..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().()));
141
142 let pool = self.poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#pool..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().();
143
144 async move {
145 let returned_to_pool = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(floating) = floating {
146 floating.return_to_poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]return_to_pool().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
147 } else {
148 false
149 };
150
151 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().returned_to_pool {
152 pool.min_connections_maintenancerust-analyzer cargo sqlx-core 0.8.3 pool/inner/impl#[`PoolInner<DB>`]min_connections_maintenance().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
153 }
154 }
155 }
156
157 fn take_and_closerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]take_and_close().(&mut self) -> impl Futurerust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#<Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#Output# = ()> + Sendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Send# + 'static {
158 // float the connection in the pool before we move into the task
159 // in case the returned `Future` isn't executed, like if it's spawned into a dying runtime
160 // https://github.com/launchbadge/sqlx/issues/1396
161 // Type hints seem to be broken by `Option` combinators in IntelliJ Rust right now (6/22).
162 let floating = self.liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#live..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|live| live.floatrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Live<DB>`]float().(self.poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#pool..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().()));
163
164 let pool = self.poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#pool..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().();
165
166 async move {
167 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(floating) = floating {
168 // Don't hold the connection forever if it hangs while trying to close
169 craterust-analyzer cargo sqlx-core 0.8.3 crate/::rtrust-analyzer cargo sqlx-core 0.8.3 rt/::timeoutrust-analyzer cargo sqlx-core 0.8.3 rt/timeout().(CLOSE_ON_DROP_TIMEOUTrust-analyzer cargo sqlx-core 0.8.3 pool/connection/CLOSE_ON_DROP_TIMEOUT., floating.closerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]close().())
170 .rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().
171 .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().();
172 }
173
174 pool.min_connections_maintenancerust-analyzer cargo sqlx-core 0.8.3 pool/inner/impl#[`PoolInner<DB>`]min_connections_maintenance().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
175 }
176 }
177 }
178
179 impl<'c, DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> craterust-analyzer cargo sqlx-core 0.8.3 crate/::acquirerust-analyzer cargo sqlx-core 0.8.3 acquire/::Acquirerust-analyzer cargo sqlx-core 0.8.3 acquire/Acquire#<'c> for &'c mut PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#<DB> {
180 type Databaserust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`&'c mut PoolConnection<DB>`][`Acquire<'c>`]Database# = DB;
181
182 type Connectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`&'c mut PoolConnection<DB>`][`Acquire<'c>`]Connection# = &'c mut <DB as Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#>::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection#;
183
184 #[inline]
185 fn acquirerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`&'c mut PoolConnection<DB>`][`Acquire<'c>`]acquire().(self) -> futures_corerust-analyzer cargo futures-core 0.3.34 crate/::futurerust-analyzer cargo futures-core 0.3.34 future/::BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'c, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`&'c mut PoolConnection<DB>`][`Acquire<'c>`]::Connectionrust-analyzer cargo sqlx-core 0.8.3 acquire/Acquire#Connection#, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>> {
186 Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::pinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]pin().(futures_utilrust-analyzer cargo futures-util 0.3.34 crate/::futurerust-analyzer cargo futures-util 0.3.34 future/::okrust-analyzer cargo futures-util 0.3.34 future/ready/ok().(&mut *rust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][DerefMut]deref_mut().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self))
187 }
188
189 #[inline]
190 fn beginrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`&'c mut PoolConnection<DB>`][`Acquire<'c>`]begin().(
191 self,
192 ) -> futures_corerust-analyzer cargo futures-core 0.3.34 crate/::futurerust-analyzer cargo futures-core 0.3.34 future/::BoxFuturerust-analyzer cargo futures-core 0.3.34 future/BoxFuture#<'c, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<craterust-analyzer cargo sqlx-core 0.8.3 crate/::transactionrust-analyzer cargo sqlx-core 0.8.3 transaction/::Transactionrust-analyzer cargo sqlx-core 0.8.3 transaction/Transaction#<'c, DB>, Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#>>
193 {
194 craterust-analyzer cargo sqlx-core 0.8.3 crate/::transactionrust-analyzer cargo sqlx-core 0.8.3 transaction/::Transactionrust-analyzer cargo sqlx-core 0.8.3 transaction/Transaction#::beginrust-analyzer cargo sqlx-core 0.8.3 transaction/impl#[`Transaction<'c, DB>`]begin().(&mut *rust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][DerefMut]deref_mut().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self)
195 }
196 }
197
198 /// Returns the connection to the [`Pool`][crate::pool::Pool] it was checked-out from.
199 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#<DB> {
200 fn droprust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`][Drop]drop().(&mut self) {
201 if self.close_on_droprust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#close_on_drop. {
202 craterust-analyzer cargo sqlx-core 0.8.3 crate/::rtrust-analyzer cargo sqlx-core 0.8.3 rt/::spawnrust-analyzer cargo sqlx-core 0.8.3 rt/spawn().(self.take_and_closerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]take_and_close().());
203 return;
204 }
205
206 // We still need to spawn a task to maintain `min_connections`.
207 if self.liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#live..is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() || self.poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#pool..optionsrust-analyzer cargo sqlx-core 0.8.3 pool/inner/PoolInner#options..min_connectionsrust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolOptions#min_connections. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]gt().0 {
208 craterust-analyzer cargo sqlx-core 0.8.3 crate/::rtrust-analyzer cargo sqlx-core 0.8.3 rt/::spawnrust-analyzer cargo sqlx-core 0.8.3 rt/spawn().(self.return_to_poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`PoolConnection<DB>`]return_to_pool().());
209 }
210 }
211 }
212
213 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> Liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#<DB> {
214 pub fn floatrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Live<DB>`]float().(self, pool: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<PoolInnerrust-analyzer cargo sqlx-core 0.8.3 pool/inner/PoolInner#<DB>>) -> Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#<DB, Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Live<DB>`]> {
215 Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating# {
216 innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner.: self,
217 // create a new guard from a previously leaked permit
218 guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard.: DecrementSizeGuardrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#::new_permitrust-analyzer cargo sqlx-core 0.8.3 pool/inner/impl#[`DecrementSizeGuard<DB>`]new_permit().(pool),
219 }
220 }
221
222 pub fn into_idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Live<DB>`]into_idle().(self) -> Idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#<DB> {
223 Idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle# {
224 liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#live.: self,
225 idle_sincerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#idle_since.: Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().(),
226 }
227 }
228 }
229
230 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for Idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#<DB> {
231 type Targetrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Idle<DB>`][Deref]Target# = Liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#<DB>;
232
233 fn derefrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Idle<DB>`][Deref]deref().(&self) -> &Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Idle<DB>`][Deref]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
234 &self.liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#live.
235 }
236 }
237
238 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for Idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#<DB> {
239 fn deref_mutrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Idle<DB>`][DerefMut]deref_mut().(&mut self) -> &mut Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Idle<DB>`][DerefMut]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
240 &mut self.liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#live.
241 }
242 }
243
244 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#<DB, Liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#<DB>> {
245 pub fn new_liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]new_live().(conn: DB::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection#, guard: DecrementSizeGuardrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#<DB>) -> Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`] {
246 Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`] {
247 innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner.: Liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live# {
248 rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw.: conn,
249 created_atrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#created_at.: Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().(),
250 },
251 guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard.,
252 }
253 }
254
255 pub fn reattachrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]reattach().(self) -> PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#<DB> {
256 let Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating# { innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner., guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard. } = self;
257
258 let pool = Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().(&guard.poolrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#pool.);
259
260 guard.cancelrust-analyzer cargo sqlx-core 0.8.3 pool/inner/impl#[`DecrementSizeGuard<DB>`]cancel().();
261 PoolConnectionrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection# {
262 liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#live.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(inner),
263 close_on_droprust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#close_on_drop.: false,
264 poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/PoolConnection#pool.,
265 }
266 }
267
268 pub fn releaserust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]release().(self) {
269 self.guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard..poolrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#pool..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T, A>`][Clone]clone().().releaserust-analyzer cargo sqlx-core 0.8.3 pool/inner/impl#[`PoolInner<DB>`]release().(self);
270 }
271
272 /// Return the connection to the pool.
273 ///
274 /// Returns `true` if the connection was successfully returned, `false` if it was closed.
275 async fn return_to_poolrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]return_to_pool().(mut self) -> bool {
276 // Immediately close the connection.
277 if self.guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard..poolrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#pool..is_closedrust-analyzer cargo sqlx-core 0.8.3 pool/inner/impl#[`PoolInner<DB>`]is_closed().() {
278 self.closerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
279 return false;
280 }
281
282 // If the connection is beyond max lifetime, close the connection and
283 // immediately create a new connection
284 if is_beyond_max_lifetimerust-analyzer cargo sqlx-core 0.8.3 pool/inner/is_beyond_max_lifetime().(&self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner., &self.guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard..poolrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#pool..optionsrust-analyzer cargo sqlx-core 0.8.3 pool/inner/PoolInner#options.) {
285 self.closerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
286 return false;
287 }
288
289 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(test) = &self.guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard..poolrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#pool..optionsrust-analyzer cargo sqlx-core 0.8.3 pool/inner/PoolInner#options..after_releaserust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolOptions#after_release. {
290 let meta = self.metadatarust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]metadata().();
291 match (test)(&mut self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner..rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw., meta).rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll(). {
292 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(true) => (),
293 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(false) => {
294 self.closerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
295 return false;
296 }
297 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) => {
298 tracingrust-analyzer cargo tracing 0.1.44 crate/::warnrust-analyzer cargo tracing 0.1.44 macros/warn!!(%error, "error from `after_release`");
299 // Connection is broken, don't try to gracefully close as
300 // something weird might happen.
301 self.close_hardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]close_hard().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
302 return false;
303 }
304 }
305 }
306
307 // test the connection on-release to ensure it is still viable,
308 // and flush anything time-sensitive like transaction rollbacks
309 // if an Executor future/stream is dropped during an `.await` call, the connection
310 // is likely to be left in an inconsistent state, in which case it should not be
311 // returned to the pool; also of course, if it was dropped due to an error
312 // this is simply a band-aid as SQLx-next connections should be able
313 // to recover from cancellations
314 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) = self.rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw..pingrust-analyzer cargo sqlx-core 0.8.3 connection/Connection#ping().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll(). {
315 tracingrust-analyzer cargo tracing 0.1.44 crate/::warnrust-analyzer cargo tracing 0.1.44 macros/warn!!(
316 %error,
317 "error occurred while testing the connection on-release",
318 );
319
320 // Connection is broken, don't try to gracefully close.
321 self.close_hardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]close_hard().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/Future#poll().;
322 false
323 } else {
324 // if the connection is still viable, release it to the pool
325 self.releaserust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]release().();
326 true
327 }
328 }
329
330 pub async fn closerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]close().(self) {
331 // This isn't used anywhere that we care about the return value
332 let _ = self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner..rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw..closerust-analyzer cargo sqlx-core 0.8.3 connection/Connection#close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().;
333
334 // `guard` is dropped as intended
335 }
336
337 pub async fn close_hardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]close_hard().(self) {
338 let _ = self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner..rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw..close_hardrust-analyzer cargo sqlx-core 0.8.3 connection/Connection#close_hard().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().;
339 }
340
341 pub fn detachrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]detach().(self) -> DB::Connectionrust-analyzer cargo sqlx-core 0.8.3 database/Database#Connection# {
342 self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner..rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw.
343 }
344
345 pub fn into_idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]into_idle().(self) -> Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#<DB, Idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#<DB>> {
346 Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating# {
347 innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner.: self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner..into_idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Live<DB>`]into_idle().(),
348 guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard.: self.guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard.,
349 }
350 }
351
352 pub fn metadatarust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Live<DB>>`]metadata().(&self) -> PoolConnectionMetadatarust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolConnectionMetadata# {
353 PoolConnectionMetadatarust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolConnectionMetadata# {
354 agerust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolConnectionMetadata#age.: self.created_atrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#created_at..elapsedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]elapsed().(),
355 idle_forrust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolConnectionMetadata#idle_for.: Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.,
356 }
357 }
358 }
359
360 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#> Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#<DB, Idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#<DB>> {
361 pub fn from_idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Idle<DB>>`]from_idle().(
362 idle: Idlerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#<DB>,
363 pool: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<PoolInnerrust-analyzer cargo sqlx-core 0.8.3 pool/inner/PoolInner#<DB>>,
364 permit: AsyncSemaphoreReleaserrust-analyzer cargo sqlx-core 0.8.3 sync/AsyncSemaphoreReleaser#<'_>,
365 ) -> Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Idle<DB>>`] {
366 Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Idle<DB>>`] {
367 innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner.: idle,
368 guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard.: DecrementSizeGuardrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#::from_permitrust-analyzer cargo sqlx-core 0.8.3 pool/inner/impl#[`DecrementSizeGuard<DB>`]from_permit().(pool, permit),
369 }
370 }
371
372 pub async fn pingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Idle<DB>>`]ping().(&mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo sqlx-core 0.8.3 error/Error#> {
373 self.liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#live..rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw..pingrust-analyzer cargo sqlx-core 0.8.3 connection/Connection#ping().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().
374 }
375
376 pub fn into_liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Idle<DB>>`]into_live().(self) -> Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#<DB, Liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#<DB>> {
377 Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating# {
378 innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner.: self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner..liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#live.,
379 guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard.: self.guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard.,
380 }
381 }
382
383 pub async fn closerust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Idle<DB>>`]close().(self) -> DecrementSizeGuardrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#<DB> {
384 if let Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(error) = self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner..liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#live..rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw..closerust-analyzer cargo sqlx-core 0.8.3 connection/Connection#close().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll(). {
385 tracingrust-analyzer cargo tracing 0.1.44 crate/::debugrust-analyzer cargo tracing 0.1.44 macros/debug!!(%error, "error occurred while closing the pool connection");
386 }
387 self.guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard.
388 }
389
390 pub async fn close_hardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Idle<DB>>`]close_hard().(self) -> DecrementSizeGuardrust-analyzer cargo sqlx-core 0.8.3 pool/inner/DecrementSizeGuard#<DB> {
391 let _ = self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner..liverust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#live..rawrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#raw..close_hardrust-analyzer cargo sqlx-core 0.8.3 connection/Connection#close_hard().().rust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().awaitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core future/future/impl#[`Pin<P>`][Future]poll().;
392
393 self.guardrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#guard.
394 }
395
396 pub fn metadatarust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, Idle<DB>>`]metadata().(&self) -> PoolConnectionMetadatarust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolConnectionMetadata# {
397 // Use a single `now` value for consistency.
398 let now = Instantrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/Instant#::nowrust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]now().();
399
400 PoolConnectionMetadatarust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolConnectionMetadata# {
401 // NOTE: the receiver is the later `Instant` and the arg is the earlier
402 // https://github.com/launchbadge/sqlx/issues/1912
403 agerust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolConnectionMetadata#age.: now.saturating_duration_sincerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]saturating_duration_since().(self.created_atrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Live#created_at.),
404 idle_forrust-analyzer cargo sqlx-core 0.8.3 pool/options/PoolConnectionMetadata#idle_for.: now.saturating_duration_sincerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/impl#[Instant]saturating_duration_since().(self.idle_sincerust-analyzer cargo sqlx-core 0.8.3 pool/connection/Idle#idle_since.),
405 }
406 }
407 }
408
409 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#, C> Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#<DB, C> {
410 type Targetrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, C>`][Deref]Target# = C;
411
412 fn derefrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, C>`][Deref]deref().(&self) -> &Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, C>`][Deref]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
413 &self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner.
414 }
415 }
416
417 impl<DB: Databaserust-analyzer cargo sqlx-core 0.8.3 database/Database#, C> DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for Floatingrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#<DB, C> {
418 fn deref_mutrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, C>`][DerefMut]deref_mut().(&mut self) -> &mut Selfrust-analyzer cargo sqlx-core 0.8.3 pool/connection/impl#[`Floating<DB, C>`][DerefMut]::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target# {
419 &mut self.innerrust-analyzer cargo sqlx-core 0.8.3 pool/connection/Floating#inner.
420 }
421 }