Open andor44 opened 9 years ago
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 upcoming changes in #102 will finally make this reality. :tada:
The previous implementation has been scrapped in favor of the upcoming 0.11.0.
Having a
'static
lifetime requirement onHandler
s seriously cripples handlers. This means you cannot have any&T
s inHandler
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 becauseApiHandler
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