rustful icon indicating copy to clipboard operation
rustful copied to clipboard

Handler shouldn't have to be 'static

Open andor44 opened this issue 10 years ago • 5 comments

Having a 'static lifetime requirement on Handlers seriously cripples handlers. This means you cannot have any &Ts in Handlers 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

andor44 avatar Jul 20 '15 12:07 andor44

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.

Ogeon avatar Jul 20 '15 13:07 Ogeon

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.

andor44 avatar Jul 20 '15 14:07 andor44

Oh, ok. You could look into Arc instead.

Ogeon avatar Jul 20 '15 14:07 Ogeon

The upcoming changes in #102 will finally make this reality. :tada:

Ogeon avatar May 14 '16 15:05 Ogeon

The previous implementation has been scrapped in favor of the upcoming 0.11.0.

Ogeon avatar Jul 16 '17 10:07 Ogeon