-
Notifications
You must be signed in to change notification settings - Fork 327
Cannot register function as middleware due to Debug trait requirements #496
Copy link
Copy link
Closed
Description
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
async fn handle_error<State: Send + Sync + 'static>(
ctx: Request<State>,
next: Next<State>,
) -> Result {
...
}
...
let mut app = tide::new();
app.middleware(handle_error);
error[E0277]: `fn(tide::request::Request<_>, tide::middleware::Next<'static, _>) -> impl std::future::Future {handle_error::<_>}` doesn't implement `std::fmt::Debug`
--> src/main.rs:97:20
|
97 | app.middleware(handle_error);
| ^^^^^^^^^^^^ `fn(tide::request::Request<_>, tide::middleware::Next<'static, _>) -> impl std::future::Future {handle_error::<_>}` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
|
= help: the trait `std::fmt::Debug` is not implemented for `fn(tide::request::Request<_>, tide::middleware::Next<'static, _>) -> impl std::future::Future {handle_error::<_>}`
This makes implementing a middleware much more complex, especially for rust beginners.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels