Skip to content
This repository has been archived by the owner on Oct 10, 2019. It is now read-only.

Does not work with tokio-postgres #17

Open
lilymara-onesignal opened this issue Aug 30, 2019 · 2 comments
Open

Does not work with tokio-postgres #17

lilymara-onesignal opened this issue Aug 30, 2019 · 2 comments

Comments

@lilymara-onesignal
Copy link

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
Copy link

cptrodgers commented Sep 14, 2019

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
Copy link
Owner

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants