lapin
lapin copied to clipboard
Consumer delegate static lifetime
Relatively new to rust so possible I'm just being dumb.
What would be a good workaround for accessing something in the closure of a consumer delegate without violating the static lifetime requirement?
In my use case, I have a connection pool for a database that I want to be able to access.
simplified pseudocode:
main() {
let pool = create_db_pool();
consumer.set_delegate(|delivery: DeliveryResult| async {
do_db_things(&pool, delivery) // compiler is unhappy because of static lifetime
}
}
errors:
`pool` is borrowed here
closure may outlive the current function, but it borrows `pool`, which is owned by the current function
may outlive borrowed value `pool`
closure obviously does not outlive the pool since the program will end there but not sure how to explicitly tell rust that it's fine to be using it