r2d2 postgres crateを使用して接続プールを作成しようとしています。このインスタンスをdbConnの別のハンドラに渡してコンパイル時に不一致エラーが発生するようにします。 PostgresConnectionManagerがManageConnection特性を実装しているので、この不一致の原因を突き止めることができません。generic構造体を返すときに型が一致しません
ありがとうございます。
extern crate r2d2;
extern crate r2d2_postgres;
use std::thread;
use r2d2:: {Pool, ManageConnection};
use r2d2_postgres::{TlsMode, PostgresConnectionManager};
fn main() {
let pool = DBPool::<PostgresConnectionManager>::new();
println!("{:?}", pool.pool);
}
struct DBPool <M: ManageConnection>{
pool: Pool<M>
}
impl<M: ManageConnection> DBPool<M> {
fn new()-> DBPool<M> {
let config = r2d2::Config::default();
let manager = PostgresConnectionManager::new("postgresql://[email protected]:26257/db?sslmode=disable", TlsMode::None).unwrap();
let p = r2d2::Pool::new(config, manager).unwrap() ;
println!("Pool p: {:?}", p);
DBPool { pool: p}
}
}
コンパイルエラー:
dbcon git:(master) ✗ cargo run
Compiling dbcon v0.1.0 (file:///Users/arvindbir/projects/rust/dbcon)
error[E0308]: mismatched types
--> src/main.rs:42:9
|
42 | DBPool { pool: p}
| ^^^^^^^^^^^^^^^^^ expected type parameter, found struct `r2d2_postgres::PostgresConnectionManager`
|
= note: expected type `DBPool<M>`
found type `DBPool<r2d2_postgres::PostgresConnectionManager>`
error: aborting due to previous error
error: Could not compile `dbcon`.
:
ので
rustc
レポート構文エラー、この問題を解決するために、あなたは 正確な型を指定する必要があります - エラーメッセージを検索するだけで3つの重複が見つかりました。質問する前に**あなたの質問を**検索してください。 – Shepmaster