use actix_web::web::Data;
use actix_web::{web, HttpResponse, Responder};
use diesel_async::pooled_connection::deadpool::Pool;
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
use diesel_async::AsyncPgConnection;
use crate::controllers::user_controller::create_user;
use actix_web::dev::Server;
use actix_web::{middleware, web, App, HttpServer};
use diesel_async::pooled_connection::deadpool::Pool;
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
use log::{error, info};
use std::env;
use std::env::var;
use std::error::Error;
use std::net::TcpListener;
/// Starts a web server on the specified listener.
///
/// # Arguments
///
/// listener - A TcpListener instance used to listen for incoming connections.
///
/// # Returns
///
/// Result<Server, Box<dyn Error>> - A Result indicating success or failure. If successful, returns a Server instance representing the running web server.
pub async fn start(listener: TcpListener) -> Result<Server, Box> {
let port = listener.local_addr().unwrap().port();
let database_url = var("DATABASE_URL").unwrap_or_else(|e| panic!("an error occurred {e}"));
let config = AsyncDieselConnectionManager::::new(database_url);
let pool = Pool::builder(config).build()?;
// let db_pool = web::Data::new(pool);
info!(">>> Starting web server on port: {} >>>", port);
let server = HttpServer::new(|| {
App::new()
.route("/api/user", web::post().to(create_user))
.app_data(pool.clone())
.wrap(middleware::Logger::default())
})
.listen(listener)?
.run();
Ok(server)
}
Versions
diesel-async = {version = "0.5.0", features = ["postgres","deadpool"]}
diesel = {version = "2.2.2", features = ["chrono", "postgres"]}
**Rust:1.82.0 nightly
**Diesel: 2.2.2
**Diesel_async:0.5.0
**Database:postgres
**Operating System: Darwin BB-Mac-Pro.attlocal.net 24.0.0 Darwin Kernel Version 24.0.0: Sat Jul 13 00:54:59 PDT 2024; root:xnu-11215.0.165.0.4~50/RELEASE_ARM64_T6031 arm64
Feature Flags
**diesel: "chrono", "postgres"
**diesel_async:"postgres","deadpool"
Problem Description
error[E0277]: the trait bound AsyncDieselConnectionManager<AsyncPgConnection>: DerefMut is not satisfied
--> src/controllers/user_controller.rs:11:16
11
pool: Data<Pool<AsyncDieselConnectionManager>>,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait DerefMut is not implemented for AsyncDieselConnectionManager<AsyncPgConnection>, which is required by AsyncDieselConnectionManager<AsyncDieselConnectionManager<AsyncPgConnection>>: deadpool::managed::Manager
= help: the trait `deadpool::managed::Manager` is implemented for `AsyncDieselConnectionManager<C>`
= note: required for `AsyncDieselConnectionManager<AsyncPgConnection>` to implement `AsyncConnection`
What are you trying to accomplish?
trying to inject Pool to app_Data() actix web
What is the expected output?
I expect the build to succeed and get connections from the pool
What is the actual output?
error[E0277]: the trait bound AsyncDieselConnectionManager<AsyncPgConnection>: DerefMut is not satisfied
--> src/controllers/user_controller.rs:11:16
11
pool: Data<Pool<AsyncDieselConnectionManager>>,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait DerefMut is not implemented for AsyncDieselConnectionManager<AsyncPgConnection>, which is required by AsyncDieselConnectionManager<AsyncDieselConnectionManager<AsyncPgConnection>>: deadpool::managed::Manager
= help: the trait `deadpool::managed::Manager` is implemented for `AsyncDieselConnectionManager<C>`
= note: required for `AsyncDieselConnectionManager<AsyncPgConnection>` to implement `AsyncConnection`
Are you seeing any additional errors?
Steps to reproduce
use actix_web::web::Data;
use actix_web::{web, HttpResponse, Responder};
use diesel_async::pooled_connection::deadpool::Pool;
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
use diesel_async::AsyncPgConnection;
Setup
use actix_web::web::Data; use actix_web::{web, HttpResponse, Responder}; use diesel_async::pooled_connection::deadpool::Pool; use diesel_async::pooled_connection::AsyncDieselConnectionManager; use diesel_async::AsyncPgConnection;
use crate::models::models::UserDto;
pub async fn create_user( user: web::Json,
pool: Data<Pool<AsyncDieselConnectionManager>>,
) -> impl Responder {
// let mut connection: &mut Pool<AsyncDieselConnectionManager>;
// con.clone_into(connection);
let mut conn = pool.get().await.unwrap();
// create_user_and_profile(, &user.user, &user.profile).await
HttpResponse::Ok().body("Ok")
}
use crate::controllers::user_controller::create_user; use actix_web::dev::Server; use actix_web::{middleware, web, App, HttpServer}; use diesel_async::pooled_connection::deadpool::Pool; use diesel_async::pooled_connection::AsyncDieselConnectionManager; use log::{error, info}; use std::env; use std::env::var; use std::error::Error; use std::net::TcpListener;
/// Starts a web server on the specified listener. /// /// # Arguments /// ///> {
let port = listener.local_addr().unwrap().port();
let database_url = var("DATABASE_URL").unwrap_or_else(|e| panic!("an error occurred {e}"));
let config = AsyncDieselConnectionManager::::new(database_url);
let pool = Pool::builder(config).build()?;
listener
- ATcpListener
instance used to listen for incoming connections. /// /// # Returns /// ///Result<Server, Box<dyn Error>>
- A Result indicating success or failure. If successful, returns aServer
instance representing the running web server. pub async fn start(listener: TcpListener) -> Result<Server, Box}
Versions
diesel-async = {version = "0.5.0", features = ["postgres","deadpool"]} diesel = {version = "2.2.2", features = ["chrono", "postgres"]}
Feature Flags
Problem Description
AsyncDieselConnectionManager<AsyncPgConnection>: DerefMut
is not satisfied --> src/controllers/user_controller.rs:11:16DerefMut
is not implemented forAsyncDieselConnectionManager<AsyncPgConnection>
, which is required byAsyncDieselConnectionManager<AsyncDieselConnectionManager<AsyncPgConnection>>: deadpool::managed::Manager
What are you trying to accomplish?
trying to inject Pool to app_Data() actix web
What is the expected output?
I expect the build to succeed and get connections from the pool
What is the actual output?
AsyncDieselConnectionManager<AsyncPgConnection>: DerefMut
is not satisfied --> src/controllers/user_controller.rs:11:16DerefMut
is not implemented forAsyncDieselConnectionManager<AsyncPgConnection>
, which is required byAsyncDieselConnectionManager<AsyncDieselConnectionManager<AsyncPgConnection>>: deadpool::managed::Manager
Are you seeing any additional errors?
Steps to reproduce
use actix_web::web::Data; use actix_web::{web, HttpResponse, Responder}; use diesel_async::pooled_connection::deadpool::Pool; use diesel_async::pooled_connection::AsyncDieselConnectionManager; use diesel_async::AsyncPgConnection;
use crate::models::models::UserDto;
pub async fn create_user( user: web::Json,
pool: Data<Pool<AsyncDieselConnectionManager>>,
) -> impl Responder {
// let mut connection: &mut Pool<AsyncDieselConnectionManager>;
// con.clone_into(connection);
let mut conn = pool.get().await.unwrap();
// create_user_and_profile(, &user.user, &user.profile).await
HttpResponse::Ok().body("Ok")
}
Checklist