You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking at the middleware documentation, there is a implementation for Fn(Request<State>, Next<'a, State>) -> BoxFuture<'a, Result>, which should allow me to register an async function as a middleware without implementing a struct and trait. Unfortunately the Server::middleware function additionally has a requirement that the middleware implements the Debug trait. So the following example fails
Yeah that's fair — maybe we should get rid of the debug requirement, but add a default method on the middleware trait that contains the middleware name.
I'm still wondering if it might be possible to register a simple async function that returns a Result. An explanation why this might not be possible would also be very appreciated.
#556 makes this easier by exposing Before and After middleware constructors. We currently cannot implement the middleware trait for async fns, so this seems to be about the best we can do until the language catches up.
Looking at the middleware documentation, there is a implementation for
Fn(Request<State>, Next<'a, State>) -> BoxFuture<'a, Result>
, which should allow me to register an async function as a middleware without implementing a struct and trait. Unfortunately theServer::middleware
function additionally has a requirement that the middleware implements theDebug
trait. So the following example failsThis makes implementing a middleware much more complex, especially for rust beginners.
The text was updated successfully, but these errors were encountered: