Handler shouldn't have to be 'static
Opened this issue · 5 comments
Having a 'static
lifetime requirement on Handler
s seriously cripples handlers. This means you cannot have any &T
s in Handler
s that aren't static also. I encountered this problem today while trying to integrate ivanceras/rustorm today with rustful with this code snippet. This doesn't work because ApiHandler
stores a &Database
, which isn't 'static
. I work around this issue by diving a bit lower and passing around the r2d2 connection pool instead, but that heavily bloats my code.
tl;dr: please make Handler
not require 'static
, it would make it a lot more flexible
I would love to do this, but it's unfortunately a restriction from the Hyper backend (see hyperium/hyper#504). You could try to use the global
field if you don't want to bloat the ApiHandler
.
I wrote this snippet on purpose to avoid using global
, in order to employ the guarantees of the type-system to ensure I have a correct and usable database context in my handlers. But thanks for the reply, I will be patiently waiting for the upstream fix then.
Oh, ok. You could look into Arc
instead.
The previous implementation has been scrapped in favor of the upcoming 0.11.0.