diff --git a/tokio-postgres/src/client.rs b/tokio-postgres/src/client.rs index ba43be6d..56e13143 100644 --- a/tokio-postgres/src/client.rs +++ b/tokio-postgres/src/client.rs @@ -197,9 +197,9 @@ impl Client { pub fn query( &mut self, statement: &Statement, - params: &[&dyn ToSql], + params: &[&(dyn ToSql + Sync)], ) -> impl Stream> { - let buf = query::encode(statement, params.iter().cloned()); + let buf = query::encode(statement, params.iter().map(|s| *s as _)); query::query(self.inner(), statement.clone(), buf) } @@ -229,9 +229,9 @@ impl Client { pub fn execute( &mut self, statement: &Statement, - params: &[&dyn ToSql], + params: &[&(dyn ToSql + Sync)], ) -> impl Future> { - let buf = query::encode(statement, params.iter().cloned()); + let buf = query::encode(statement, params.iter().map(|s| *s as _)); query::execute(self.inner(), buf) } @@ -262,7 +262,7 @@ impl Client { pub fn copy_in( &mut self, statement: &Statement, - params: &[&dyn ToSql], + params: &[&(dyn ToSql + Sync)], stream: S, ) -> impl Future> where @@ -271,7 +271,7 @@ impl Client { ::Buf: 'static + Send, S::Error: Into>, { - let buf = query::encode(statement, params.iter().cloned()); + let buf = query::encode(statement, params.iter().map(|s| *s as _)); copy_in::copy_in(self.inner(), buf, stream) } @@ -283,9 +283,9 @@ impl Client { pub fn copy_out( &mut self, statement: &Statement, - params: &[&dyn ToSql], + params: &[&(dyn ToSql + Sync)], ) -> impl Stream> { - let buf = query::encode(statement, params.iter().cloned()); + let buf = query::encode(statement, params.iter().map(|s| *s as _)); copy_out::copy_out(self.inner(), buf) } diff --git a/tokio-postgres/src/transaction.rs b/tokio-postgres/src/transaction.rs index 0489f09f..64b86abf 100644 --- a/tokio-postgres/src/transaction.rs +++ b/tokio-postgres/src/transaction.rs @@ -95,7 +95,7 @@ impl<'a> Transaction<'a> { pub fn query( &mut self, statement: &Statement, - params: &[&dyn ToSql], + params: &[&(dyn ToSql + Sync)], ) -> impl Stream> { self.client.query(statement, params) } @@ -119,7 +119,7 @@ impl<'a> Transaction<'a> { pub fn execute( &mut self, statement: &Statement, - params: &[&dyn ToSql], + params: &[&(dyn ToSql + Sync)], ) -> impl Future> { self.client.execute(statement, params) } @@ -150,10 +150,10 @@ impl<'a> Transaction<'a> { pub fn bind( &mut self, statement: &Statement, - params: &[&dyn ToSql], + params: &[&(dyn ToSql + Sync)], ) -> impl Future> { // https://github.com/rust-lang/rust/issues/63032 - let buf = bind::encode(statement, params.iter().cloned()); + let buf = bind::encode(statement, params.iter().map(|s| *s as _)); bind::bind(self.client.inner(), statement.clone(), buf) } @@ -189,7 +189,7 @@ impl<'a> Transaction<'a> { pub fn copy_in( &mut self, statement: &Statement, - params: &[&dyn ToSql], + params: &[&(dyn ToSql + Sync)], stream: S, ) -> impl Future> where @@ -205,7 +205,7 @@ impl<'a> Transaction<'a> { pub fn copy_out( &mut self, statement: &Statement, - params: &[&dyn ToSql], + params: &[&(dyn ToSql + Sync)], ) -> impl Stream> { self.client.copy_out(statement, params) } diff --git a/tokio-postgres/tests/test/types/mod.rs b/tokio-postgres/tests/test/types/mod.rs index 89cce955..09b34cc2 100644 --- a/tokio-postgres/tests/test/types/mod.rs +++ b/tokio-postgres/tests/test/types/mod.rs @@ -27,7 +27,7 @@ mod uuid_07; async fn test_type(sql_type: &str, checks: &[(T, S)]) where - T: PartialEq + for<'a> FromSqlOwned + ToSql, + T: PartialEq + for<'a> FromSqlOwned + ToSql + Sync, S: fmt::Display, { let mut client = connect("user=postgres").await; @@ -656,3 +656,30 @@ async fn inet() { ) .await; } + +#[tokio::test] +async fn check_send() { + fn is_send(_: &T) {} + + let mut client = connect("user=postgres").await; + + let f = client.prepare("SELECT $1::TEXT"); + is_send(&f); + let stmt = f.await.unwrap(); + + let f = client.query(&stmt, &[&"hello"]); + is_send(&f); + + let f = client.execute(&stmt, &[&"hello"]); + is_send(&f); + + let f = client.transaction(); + is_send(&f); + let mut trans = f.await.unwrap(); + + let f = trans.query(&stmt, &[&"hello"]); + is_send(&f); + + let f = trans.execute(&stmt, &[&"hello"]); + is_send(&f); +}