Ogeon/rustful

Handler shouldn't have to be 'static

Opened this issue · 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

Ogeon commented

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.

Ogeon commented

Oh, ok. You could look into Arc instead.

Ogeon commented

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

Ogeon commented

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