Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

README example compilation errors #23

Closed
@dpetersen

Description

@dpetersen

I have been working with Diesel a bit using it'sPgConnection directly, and I'm trying to actually get a connection pool hooked up via R2D2, but I've run into an error that I can't seem to get around:

the trait `r2d2_postgres::postgres::tls::MakeTlsConnect<r2d2_postgres::postgres::Socket>` is not implemented for `postgres::NoTls`

When trying to instantiate anr2d2_postgres::PostgresConnectionManager like:

PostgresConnectionManager::new(database_url.parse().unwrap(), postgres::tls::NoTls);

I finally just made a new Rust project to run the example code in theREADME that I was using as my guide, but it seems to be failing with the same error. My standalone project'sdependencies block looks like:

[dependencies]r2d2 ="0.8.9"r2d2_postgres ="0.16.0"postgres ="0.18.1"

and mysrc/main.rs looks like this (ripped straight from this project'sREADME):

use postgres::{Client,NoTls};use r2d2_postgres::PostgresConnectionManager;use std::thread;fnmain(){let manager =PostgresConnectionManager::new("host=localhost user=postgres".parse().unwrap(),NoTls);let pool = r2d2::Pool::new(manager).unwrap();for iin0..10i32{let pool = pool.clone();                                                                       thread::spawn(move ||{letmut client = pool.get().unwrap();                                                          client.execute("INSERT INTO foo (bar) VALUES ($1)",&[&i]).unwrap();});}}

Runningcargo build results in the following rather lengthy set of errors. You can see the same trait implementation error in this near the top:

   Compiling test-postgres v0.1.0 (/home/dpetersen/dev/test-postgres)warning: unused import: `Client` --> src/main.rs:1:16  |1 | use postgres::{Client, NoTls};  |                ^^^^^^  |  = note: `#[warn(unused_imports)]` on by defaulterror[E0277]: the trait bound `postgres::NoTls: r2d2_postgres::postgres::tls::MakeTlsConnect<r2d2_postgres::postgres::Socket>` is not satisfied --> src/main.rs:7:89  |7 |         PostgresConnectionManager::new("host=localhost user=postgres".parse().unwrap(), NoTls);  |                                                                                         ^^^^^ the trait `r2d2_postgres::postgres::tls::MakeTlsConnect<r2d2_postgres::postgres::Socket>` is not implemented for `postgres::NoTls`  |  = note: required by `r2d2_postgres::PostgresConnectionManager::<T>::new`error[E0277]: the trait bound `postgres::NoTls: r2d2_postgres::postgres::tls::MakeTlsConnect<r2d2_postgres::postgres::Socket>` is not satisfied --> src/main.rs:8:32  |8 |     let pool = r2d2::Pool::new(manager).unwrap();  |                                ^^^^^^^ the trait `r2d2_postgres::postgres::tls::MakeTlsConnect<r2d2_postgres::postgres::Socket>` is not implemented for `postgres::NoTls`  |  = note: required because of the requirements on the impl of `r2d2::ManageConnection` for `r2d2_postgres::PostgresConnectionManager<postgres::NoTls>`  = note: required by `r2d2::Pool::<M>::new`error[E0277]: the trait bound `postgres::NoTls: r2d2_postgres::postgres::tls::MakeTlsConnect<r2d2_postgres::postgres::Socket>` is not satisfied   --> src/main.rs:8:16    |8   |     let pool = r2d2::Pool::new(manager).unwrap();    |                ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `r2d2_postgres::postgres::tls::MakeTlsConnect<r2d2_postgres::postgres::Socket>` is not implemented for `postgres::NoTls`    |    ::: /home/dpetersen/.cargo/registry/src/github.com-1ecc6299db9ec823/r2d2-0.8.9/src/lib.rs:319:8    |319 |     M: ManageConnection;    |        ---------------- required by this bound in `r2d2::Pool`    |    = note: required because of the requirements on the impl of `r2d2::ManageConnection` for `r2d2_postgres::PostgresConnectionManager<postgres::NoTls>`error[E0599]: no method named `clone` found for struct `r2d2::Pool<r2d2_postgres::PostgresConnectionManager<postgres::NoTls>>` in the current scope   --> src/main.rs:11:25    |11  |           let pool = pool.clone();    |                           ^^^^^ method not found in `r2d2::Pool<r2d2_postgres::PostgresConnectionManager<postgres::NoTls>>`    |    ::: /home/dpetersen/.cargo/registry/src/github.com-1ecc6299db9ec823/r2d2_postgres-0.16.0/src/lib.rs:37:1    |37  |   pub struct PostgresConnectionManager<T> {    |   --------------------------------------- doesn't satisfy `_: r2d2::ManageConnection`    |    ::: /home/dpetersen/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/clone.rs:122:8    |122 |       fn clone(&self) -> Self;    |          -----    |          |    |          the method is available for `std::sync::Arc<r2d2::Pool<r2d2_postgres::PostgresConnectionManager<postgres::NoTls>>>` here    |          the method is available for `std::rc::Rc<r2d2::Pool<r2d2_postgres::PostgresConnectionManager<postgres::NoTls>>>` here    |    ::: /home/dpetersen/.cargo/registry/src/github.com-1ecc6299db9ec823/r2d2-0.8.9/src/lib.rs:317:1    |317 | / pub struct Pool<M>(Arc<SharedPool<M>>)318 | | where319 | |     M: ManageConnection;    | |________________________- doesn't satisfy `_: std::clone::Clone`    |    = note: the method `clone` exists but the following trait bounds were not satisfied:            `r2d2_postgres::PostgresConnectionManager<postgres::NoTls>: r2d2::ManageConnection`            which is required by `r2d2::Pool<r2d2_postgres::PostgresConnectionManager<postgres::NoTls>>: std::clone::Clone`error: aborting due to 4 previous errors; 1 warning emittedSome errors have detailed explanations: E0277, E0599.For more information about an error, try `rustc --explain E0277`.error: could not compile `test-postgres`.To learn more, run the command again with --verbose.

I am running everything locally at the moment and so I can't use TLS, as far as I know. I have checked at all the available changelogs I can find, I've ensured I'm using the newest version of all the relevant crates. I'm still fairly bad at Rust and so I don't really understand how I can get around this issue, but I've spent a couple hours unsuccessfully trying to get this working. I've done a fair amount of Googling and haven't found anyone with a similar issue, so I have a bad feeling I'm screwing something up. I've tried every example I can find on the Internet of somebody trying to set up a connection pool, with no luck.

I really appreciate all the work you've done building such awesome Postgres support in Rust, and I'm sorry to bother you with something this simple. Hopefully, you can point me in the right direction. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp