sfackler / rust-postgres-derive

Apache License 2.0
35 stars 13 forks source link

Does not work with tokio-postgres #17

Open lilymara-onesignal opened 4 years ago

lilymara-onesignal commented 4 years ago

Trying to use this crate with the tokio-postgres crate will not work, as this crate expects to implement postgres::ToSql, and not tokio_postgres::ToSql. Even though the two traits are identical.

cptrodgers commented 4 years ago

Hi @nate-onesignal, Compatible is one of problems that you need to deal with Rust code (TypeSafe). I think you can use this style for this case.

pub trait ToSqlCompat {
    fn compat_sql() -> postgres::ToSql;
}

impl ToSqlCompat for tokio_postgres::ToSql {
    fn compat_sql() -> postgres::ToSql {
        ... // Map logic from tokio_postgres -> postgres here.
    }
}

let a: tokio_postgres::ToSql = tokio_postgres::ToSql::new(); // I asumes this.
a.compat_sql();

I just find something about Postgres in Rust. So I comes here. I hope this can help you.

sfackler commented 4 years ago

postgres::ToSql and tokio_postgres::ToSql are the same trait, so as a workaround you can just depend on the postgres crate as well.

I think the "right" solution here is to split out a postgres-types crate with a derive Cargo feature so there's a single canonical place for the traits to be defined in and named from.