Migrated from halcyonnouveau/clorinde#117, originally reported by @TimDiekmann on 2025-06-10.
The generated code generates a new trait GenericClient. This is basically a copy of tokio_postgres::GenericClient, however, it's not the same trait.
The trait is implemented on tokio_postgres::Client and tokio_postgres::Transaction, but not on a generic T: tokio_postgres::GenericClient. This means in a generic context
async fn takes_client(client: &impl GenericClient) {
// do something with `clorinde::GenericClient`
}
this will error.
If this code snippet would be generated instead, everything would work as expected:
impl<C: tokio_postgres::GenericClient + Sync> GenericClient for C {
async fn prepare(&self, query: &str) -> Result<Statement, Error> {
tokio_postgres::GenericClient::prepare(self, query).await
}
async fn execute<T>(
&self,
query: &T,
params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
) -> Result<u64, Error>
where
T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
{
tokio_postgres::GenericClient::execute(self, query, params).await
}
async fn query_one<T>(
&self,
statement: &T,
params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
) -> Result<tokio_postgres::Row, Error>
where
T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
{
tokio_postgres::GenericClient::query_one(self, statement, params).await
}
async fn query_opt<T>(
&self,
statement: &T,
params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
) -> Result<Option<tokio_postgres::Row>, Error>
where
T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
{
tokio_postgres::GenericClient::query_opt(self, statement, params).await
}
async fn query<T>(
&self,
query: &T,
params: &[&(dyn tokio_postgres::types::ToSql + Sync)],
) -> Result<Vec<tokio_postgres::Row>, Error>
where
T: ?Sized + tokio_postgres::ToStatement + Sync + Send,
{
tokio_postgres::GenericClient::query(self, query, params).await
}
async fn query_raw<T, I>(&self, statement: &T, params: I) -> Result<RowStream, Error>
where
T: ?Sized + ToStatement + Sync + Send,
I: IntoIterator + Sync + Send,
I::IntoIter: ExactSizeIterator,
I::Item: BorrowToSql,
{
tokio_postgres::GenericClient::query_raw(self, statement, params).await
}
}
Btw, the GenericClient does not need the Send bound:
pub trait GenericClient: Sync {
The generated code generates a new trait
GenericClient. This is basically a copy oftokio_postgres::GenericClient, however, it's not the same trait.The trait is implemented on
tokio_postgres::Clientandtokio_postgres::Transaction, but not on a genericT: tokio_postgres::GenericClient. This means in a generic contextthis will error.
If this code snippet would be generated instead, everything would work as expected:
Btw, the
GenericClientdoes not need theSendbound: