Replies: 1 comment 3 replies
-
I converted this to a discussion as it's not a issue in diesel-async, but a support question. Please use the discussion forum for future similar questions as we use the issue tracker to track actual bugs. Future posts there will be handled as bug reports and closed as invalid without further explanations. The error message already provides all relevant information to resolve this issue. In particular this part:
You just mixed up the types in your |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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
///
/// *
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> {
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::<diesel_async::AsyncPgConnection>::new(database_url);
let pool = Pool::builder(config).build()?;
}
Versions
diesel-async = {version = "0.5.0", features = ["postgres","deadpool"]}
diesel = {version = "2.2.2", features = ["chrono", "postgres"]}
Feature Flags
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 forAsyncDieselConnectionManager<AsyncPgConnection>
, which is required byAsyncDieselConnectionManager<AsyncDieselConnectionManager<AsyncPgConnection>>: deadpool::managed::Manager
|
= help: the trait
deadpool::managed::Manager
is implemented forAsyncDieselConnectionManager<C>
= note: required for
AsyncDieselConnectionManager<AsyncPgConnection>
to implementAsyncConnection
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 forAsyncDieselConnectionManager<AsyncPgConnection>
, which is required byAsyncDieselConnectionManager<AsyncDieselConnectionManager<AsyncPgConnection>>: deadpool::managed::Manager
|
= help: the trait
deadpool::managed::Manager
is implemented forAsyncDieselConnectionManager<C>
= note: required for
AsyncDieselConnectionManager<AsyncPgConnection>
to implementAsyncConnection
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
closed if this is not the case)
Beta Was this translation helpful? Give feedback.
All reactions