`GenericClient` is not implemented for `T: tokio_postgres::GenericClient`

オープン
#286 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
postgresql, rust
領域
backend, databases

調査の方向性

Find the code that generates the GenericClient trait and its implementations; the issue does not name the file or tests. Compare the generated implementations with the proposed blanket implementation for T: tokio_postgres::GenericClient + Sync, and check whether the trait needs a Send bound. Done means generated code supports generic clients and the shown generic function compiles.

索引モデルが issue の本文から書いたものです。

説明

bug codegen

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 {
主要言語
Rust
スター
1.2k
フォーク
77
平均マージ
5日 12時間
マージ済み PR(30日)
1

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

cornucopia-rs/cornucopia のほかの issue

cornucopia-rs/cornucopia の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。