Skip to content

Commit d752433

Browse files
committed
Add back async_trait to GenericClient interface
1 parent 88a11a8 commit d752433

File tree

3 files changed

+26
-37
lines changed

3 files changed

+26
-37
lines changed

postgres/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
## [Unreleased]
1111

12+
- Add back `async_trait` to the `GenericClient` trait.
13+
The removal of `async_trait` caused some errors for code using
14+
the generic client interface. A test was added to ensure future
15+
removals of `async_trait` will not cause this code to break.
16+
1217
## [0.13.2] - 2024-05-07
1318

1419
- Add WASM support

postgres/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ rt_async-std_1 = ["deadpool/rt_async-std_1"]
2020
serde = ["deadpool/serde", "dep:serde"]
2121

2222
[dependencies]
23+
async-trait = "0.1.80"
2324
deadpool = { path = "../", version = "0.12.0", default-features = false, features = [
2425
"managed",
2526
] }

postgres/src/generic_client.rs

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
//! - The `client()` method is not available.
44
//! - The `prepare_cached()` and `prepare_typed_cached()` are
55
//! added.
6-
use std::future::Future;
7-
86
use tokio_postgres::types::{BorrowToSql, ToSql, Type};
97
use tokio_postgres::RowStream;
108
use tokio_postgres::{Error, Row, Statement, ToStatement};
119

10+
use async_trait::async_trait;
11+
1212
use crate::{Client, ClientWrapper, Transaction};
1313

1414
mod private {
@@ -18,96 +18,78 @@ mod private {
1818
/// A trait allowing abstraction over connections and transactions.
1919
///
2020
/// This trait is "sealed", and cannot be implemented outside of this crate.
21+
#[async_trait]
2122
pub trait GenericClient: Sync + private::Sealed {
2223
/// Like `Client::execute`.
23-
fn execute<T>(
24-
&self,
25-
query: &T,
26-
params: &[&(dyn ToSql + Sync)],
27-
) -> impl Future<Output = Result<u64, Error>> + Send
24+
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
2825
where
2926
T: ?Sized + ToStatement + Sync + Send;
3027

3128
/// Like `Client::execute_raw`.
32-
fn execute_raw<P, I, T>(
33-
&self,
34-
statement: &T,
35-
params: I,
36-
) -> impl Future<Output = Result<u64, Error>> + Send
29+
async fn execute_raw<P, I, T>(&self, statement: &T, params: I) -> Result<u64, Error>
3730
where
3831
T: ?Sized + ToStatement + Sync + Send,
3932
P: BorrowToSql,
4033
I: IntoIterator<Item = P> + Sync + Send,
4134
I::IntoIter: ExactSizeIterator;
4235

4336
/// Like `Client::query`.
44-
fn query<T>(
45-
&self,
46-
query: &T,
47-
params: &[&(dyn ToSql + Sync)],
48-
) -> impl Future<Output = Result<Vec<Row>, Error>> + Send
37+
async fn query<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<Vec<Row>, Error>
4938
where
5039
T: ?Sized + ToStatement + Sync + Send;
5140

5241
/// Like `Client::query_one`.
53-
fn query_one<T>(
42+
async fn query_one<T>(
5443
&self,
5544
statement: &T,
5645
params: &[&(dyn ToSql + Sync)],
57-
) -> impl Future<Output = Result<Row, Error>> + Send
46+
) -> Result<Row, Error>
5847
where
5948
T: ?Sized + ToStatement + Sync + Send;
6049

6150
/// Like `Client::query_opt`.
62-
fn query_opt<T>(
51+
async fn query_opt<T>(
6352
&self,
6453
statement: &T,
6554
params: &[&(dyn ToSql + Sync)],
66-
) -> impl Future<Output = Result<Option<Row>, Error>> + Send
55+
) -> Result<Option<Row>, Error>
6756
where
6857
T: ?Sized + ToStatement + Sync + Send;
6958

7059
/// Like `Client::query_raw`.
71-
fn query_raw<T, P, I>(
72-
&self,
73-
statement: &T,
74-
params: I,
75-
) -> impl Future<Output = Result<RowStream, Error>> + Send
60+
async fn query_raw<T, P, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
7661
where
7762
T: ?Sized + ToStatement + Sync + Send,
7863
P: BorrowToSql,
7964
I: IntoIterator<Item = P> + Sync + Send,
8065
I::IntoIter: ExactSizeIterator;
8166

8267
/// Like `Client::prepare`.
83-
fn prepare(&self, query: &str) -> impl Future<Output = Result<Statement, Error>> + Send;
68+
async fn prepare(&self, query: &str) -> Result<Statement, Error>;
8469

8570
/// Like `Client::prepare_typed`.
86-
fn prepare_typed(
71+
async fn prepare_typed(
8772
&self,
8873
query: &str,
8974
parameter_types: &[Type],
90-
) -> impl Future<Output = Result<Statement, Error>> + Send;
75+
) -> Result<Statement, Error>;
9176

9277
/// Like [`Client::prepare_cached`].
93-
fn prepare_cached(&self, query: &str) -> impl Future<Output = Result<Statement, Error>> + Send;
78+
async fn prepare_cached(&self, query: &str) -> Result<Statement, Error>;
9479

9580
/// Like [`Client::prepare_typed_cached`]
96-
fn prepare_typed_cached(
97-
&self,
98-
query: &str,
99-
types: &[Type],
100-
) -> impl Future<Output = Result<Statement, Error>> + Send;
81+
async fn prepare_typed_cached(&self, query: &str, types: &[Type]) -> Result<Statement, Error>;
10182

10283
/// Like `Client::transaction`.
103-
fn transaction(&mut self) -> impl Future<Output = Result<Transaction<'_>, Error>> + Send;
84+
async fn transaction(&mut self) -> Result<Transaction<'_>, Error>;
10485

10586
/// Like `Client::batch_execute`.
106-
fn batch_execute(&self, query: &str) -> impl Future<Output = Result<(), Error>> + Send;
87+
async fn batch_execute(&self, query: &str) -> Result<(), Error>;
10788
}
10889

10990
impl private::Sealed for Client {}
11091

92+
#[async_trait]
11193
impl GenericClient for Client {
11294
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>
11395
where
@@ -196,6 +178,7 @@ impl GenericClient for Client {
196178

197179
impl private::Sealed for Transaction<'_> {}
198180

181+
#[async_trait]
199182
#[allow(clippy::needless_lifetimes)]
200183
impl GenericClient for Transaction<'_> {
201184
async fn execute<T>(&self, query: &T, params: &[&(dyn ToSql + Sync)]) -> Result<u64, Error>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy