Skip to content

Unable to specify the type for sqlite pool #178

@pickfire

Description

@pickfire

Setup

Versions

  • Rust: rustc 1.80.0 (051478957 2024-07-21)
  • Diesel: 2.2.0
  • Diesel_async: 0.5
  • Database: sqlite
  • Operating System Linux mi 6.10.3-zen1-2-zen #1 ZEN SMP PREEMPT_DYNAMIC Tue, 06 Aug 2024 07:47:21 +0000 x86_64 GNU/Linux (arch)

Feature Flags

  • diesel: chrono, returning_clauses_for_sqlite_3_35
  • diesel_async: sync-connection-wrapper, async-connection-wrapper, sqlite, deadpool

Problem Description

Unable to write out the type for sqlite pooled connection.

What are you trying to accomplish?

Using pooled connection for teloxide, it does dependency injection based on type, however I am unable to explicitly put out the type Pool<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>>. The inferred type from rust-analyzer

image

What is the expected output?

The inferred type should be usable when explicitly typed down.

let _pool: Pool<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>> = Pool::builder(config).build().unwrap();

What is the actual output?

image

Are you seeing any additional errors?

errors
error[E0277]: the trait bound `AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>: PoolableConnection` is not satisfied
   --> src/main.rs:14:16
    |
14  |     let _pool: Pool<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>> = Pool::builder(co...
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `PoolableConnection` is not implemented for `AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>`, which is required by `AsyncDieselConnectionManager<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>>: deadpool::managed::Manager`
    |
    = help: the trait `PoolableConnection` is implemented for `SyncConnectionWrapper<C>`
    = note: required for `AsyncDieselConnectionManager<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>>` to implement `deadpool::managed::Manager`
note: required by a bound in `deadpool::managed::Pool`
   --> /home/ivan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deadpool-0.12.1/src/managed/mod.rs:249:20
    |
249 | pub struct Pool<M: Manager, W: From<Object<M>> = Object<M>> {
    |                    ^^^^^^^ required by this bound in `Pool`

error[E0277]: the trait bound `AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>: DerefMut` is not satisfied
   --> src/main.rs:14:16
    |
14  |     let _pool: Pool<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>> = Pool::builder(co...
    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `DerefMut` is not implemented for `AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>`, which is required by `AsyncDieselConnectionManager<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>>: deadpool::managed::Manager`
    |
    = help: the trait `deadpool::managed::Manager` is implemented for `AsyncDieselConnectionManager<C>`
    = note: required for `AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>` to implement `AsyncConnection`
    = note: required for `AsyncDieselConnectionManager<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>>` to implement `deadpool::managed::Manager`
note: required by a bound in `deadpool::managed::Pool`
   --> /home/ivan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/deadpool-0.12.1/src/managed/mod.rs:249:20
    |
249 | pub struct Pool<M: Manager, W: From<Object<M>> = Object<M>> {
    |                    ^^^^^^^ required by this bound in `Pool`

error[E0308]: mismatched types
  --> src/main.rs:14:94
   |
14 | ...l: Pool<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>> = Pool::builder(config).build().unwrap...
   |       ---------------------------------------------------------------------------   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `AsyncDieselConnectionManager<SyncConnectionWrapper<...>>`, found `SyncConnectionWrapper<SqliteConnection>`
   |       |
   |       expected due to this
   |
   = note: expected struct `Pool<AsyncDieselConnectionManager<AsyncDieselConnectionManager<...>>>`
              found struct `deadpool::managed::Pool<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>>`
   = note: the full type name has been written to '/home/ivan/src/pickfire/rs/diesel-async-pool/target/debug/deps/diesel_async_pool-d703ecf4a14c8b60.long-type-12503167683362586601.txt'
   = note: consider using `--verbose` to print the full type name to the console

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `diesel-async-pool` (bin "diesel-async-pool") due to 3 previous errors

Steps to reproduce

  1. cargo new diesel-async-pool
  2. Add the following code
src/main.rs
use diesel::sqlite::SqliteConnection;
use diesel_async::pooled_connection::deadpool::Pool;
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
use diesel_async::sync_connection_wrapper::SyncConnectionWrapper;

#[tokio::main]
async fn main() {
    let db_url = std::env::var("DATABASE_URL").expect("Env var `DATABASE_URL` not set");

    let config =
        AsyncDieselConnectionManager::<SyncConnectionWrapper<SqliteConnection>>::new(db_url);
    let _pool = Pool::builder(config).build().unwrap();
    // putting the type fails
    let _pool: Pool<AsyncDieselConnectionManager<SyncConnectionWrapper<SqliteConnection>>> = Pool::builder(config).build().unwrap();
}
Cargo.toml
[package]
name = "diesel-async-pool"
version = "0.1.0"
edition = "2021"

[dependencies]
tokio = { version = "1.28.2", default-features = false, features = ["macros", "rt-multi-thread", "sync"] }
diesel = { version = "2.2.0", default-features = false, features = ["chrono", "returning_clauses_for_sqlite_3_35"] }
diesel-async = { version = "0.5", features = ["sync-connection-wrapper", "async-connection-wrapper", "sqlite", "deadpool"] }
  1. Run cargo check

Checklist

  • I have already looked over the issue tracker for similar possible closed issues.
  • This issue can be reproduced on Rust's stable channel. (Your issue will be
    closed if this is not the case)
  • This issue can be reproduced without requiring a third party crate

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationhelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions