Ogeon / rustful

[OUTDATED] A light HTTP framework for Rust
https://docs.rs/rustful
Apache License 2.0
862 stars 51 forks source link

Handler shouldn't have to be 'static #51

Open andor44 opened 9 years ago

andor44 commented 9 years ago

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 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.

andor44 commented 9 years ago

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 9 years ago

Oh, ok. You could look into Arc instead.

Ogeon commented 8 years ago

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

Ogeon commented 7 years ago

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