static mut DB_POOL: Mutex<Pool<PostgresConnectionManager<NoTls>>> = ?????;
unsafe {
DB_POOL = Mutex::from(bb8::Pool::builder()
.max_size(20)
.build(
PostgresConnectionManager::new_from_stringlike(
format!(
"postgresql://{}:{}@{}:{}/{}",
"username", "password", "localhost", "5432", "dbname",
),
bb8_postgres::tokio_postgres::NoTls,
)
.unwrap(),
)
.await
.unwrap());
}
I'm trying to use this method to get a static reference to my db credentials so I can use them anywhere without hassle of passing them around to every function in the chain.
- I'm not sure what default value to give the initial static variable
- Is this safe as long as I use a mutex... do I even need a mutex since I believe I'm just reading the value after it's initial assignment?