tower-rs / tower

async fn(Request) -> Result<Response, Error>
https://docs.rs/tower
MIT License
3.56k stars 281 forks source link

Extending `Building a middleware from scratch` guide #751

Closed samueljoli closed 11 months ago

samueljoli commented 1 year ago

The Building a middleware from scratch is a great guide, I think it would be an improvement if the following steps were added:

impl Layer for TimeoutLayer { type Service = Timeout;

fn layer(&self, service: S) -> Self::Service {
    Timeout::new(service, self.timeout)
}

}


- [Error handling for middleware](https://docs.rs/axum/latest/axum/middleware/index.html#error-handling-for-middleware)

- Using the layer (integration with `ServiceBuilder`