Skip to content

Commit 1bdbeda

Browse files
Impl AsMut for advisory lock types (launchbadge#2520) (launchbadge#2554)
The documentation for `PgAdvisoryLockGuard` lists a set of types that should be able to be passed to it, but when actually trying to do so, compilation would fail due to missing `AsMut` trait implementations for those types. This commit adds the missing `AsMut` impls so that `Transaction` and `PgConnection` can be used as type parameters to `PgAdvisoryLockGuard`, as expected. For reference: launchbadge#2520
1 parent e2ce463 commit 1bdbeda

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

sqlx-core/src/transaction.rs

+10
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ where
197197
}
198198
}
199199

200+
// Implement `AsMut<DB::Connection>` so `Transaction` can be given to a
201+
// `PgAdvisoryLockGuard`.
202+
//
203+
// See: https://github.com/launchbadge/sqlx/issues/2520
204+
impl<'c, DB: Database> AsMut<DB::Connection> for Transaction<'c, DB> {
205+
fn as_mut(&mut self) -> &mut DB::Connection {
206+
&mut self.connection
207+
}
208+
}
209+
200210
impl<'c, 't, DB: Database> crate::acquire::Acquire<'t> for &'t mut Transaction<'c, DB> {
201211
type Database = DB;
202212

sqlx-postgres/src/connection/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,13 @@ impl Connection for PgConnection {
213213
!self.stream.write_buffer().is_empty()
214214
}
215215
}
216+
217+
// Implement `AsMut<Self>` so that `PgConnection` can be wrapped in
218+
// a `PgAdvisoryLockGuard`.
219+
//
220+
// See: https://github.com/launchbadge/sqlx/issues/2520
221+
impl AsMut<PgConnection> for PgConnection {
222+
fn as_mut(&mut self) -> &mut PgConnection {
223+
self
224+
}
225+
}

0 commit comments

Comments
 (0)