I'm trying to understand how to pass an Arc<Mutex<T>>
to another function. Here is my code, I removed part of it for clarity:
pub struct Pool {
inner: Arc<Mutex<PostgresDb>>,
}
fn main() {
let postgres: Arc<Mutex<PostgresDb>>; //removed creation of the instance
setup(&postgres)
}
fn setup(postgres: &Arc<Mutex<PostgresDb>>) -> () {
let pool = Arc::new(Pool::new(*postgres));
}
I'm getting the error:
cannot move out of `*postgres` which is behind a shared reference
let pool = Arc::new(Pool::new(*postgres));
move occurs because `*postgres` has type `Arc<Mutex<PostgresDb>>`, which does not implement the `Copy` trait
How do I correctly pass postgres
?