Impl AsMut for advisory lock types (#2520) (#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: https://github.com/launchbadge/sqlx/issues/2520
This commit is contained in:
Andrew Lilley Brinker
2023-06-30 16:53:14 -07:00
committed by GitHub
parent e2ce463af8
commit 1bdbedabdc
2 changed files with 20 additions and 0 deletions

View File

@@ -213,3 +213,13 @@ impl Connection for PgConnection {
!self.stream.write_buffer().is_empty()
}
}
// Implement `AsMut<Self>` so that `PgConnection` can be wrapped in
// a `PgAdvisoryLockGuard`.
//
// See: https://github.com/launchbadge/sqlx/issues/2520
impl AsMut<PgConnection> for PgConnection {
fn as_mut(&mut self) -> &mut PgConnection {
self
}
}