static Pool
Closed this issue · 1 comments
I am implementing a connection pool using bb8
. I need this because our connections are async
. I need to make a static version of the pool, to do that I am using tokio::sync::OnceCell
. The OnceCell
requires a static like this:
static ONCE: OnceCell<bb8::Pool<MyDbConnectionManager>> = OnceCell::const_new();
The global accessor fn has an API like this:
pub async fn get_db_conn() -> bb8::PooledConnection<'static, &'static MyDbConnectionManager> {
Because OnceCell
requires the &'static
ref, I don't know how to get my value back in that type. bb8
has a builder that creates the type as bb8::PooledConnection<MyDbConnectionManager>
(this is mandated by the trait), is there any way I can convert that to: bb8::PooledConnection<'static, &'static MyDbConnectionManager>
?
If there is a better way to do this let me know, my goal is to have a static connection pool that I can access.
I worked out a way to do this, I need to get the pool
first from a OnceCell
and then get the connection from that. This keeps the scope smaller. It is some boilerplate but it works fine.