From da4e323578e868ff720d409e7c63dc41fa00bd3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Bizjak?= Date: Sun, 25 Jul 2021 22:02:28 +0200 Subject: [PATCH] Implement BorrowToSql for an additional type. Closes #811. --- postgres-types/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs index 4c559b95..59ec4f81 100644 --- a/postgres-types/src/lib.rs +++ b/postgres-types/src/lib.rs @@ -1042,6 +1042,19 @@ impl BorrowToSql for &dyn ToSql { } } +impl sealed::Sealed for &(dyn ToSql + Sync) {} + +/// In async contexts it is sometimes necessary to have the additional +/// Sync requirement on parameters for queries since this enables the +/// resulting Futures to be Send, hence usable in, e.g., tokio::spawn. +/// This instance is provided for those cases. +impl BorrowToSql for &(dyn ToSql + Sync) { + #[inline] + fn borrow_to_sql(&self) -> &dyn ToSql { + *self + } +} + impl sealed::Sealed for T where T: ToSql {} impl BorrowToSql for T