diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 26ed1fae..5930a1e1 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -9,9 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **added:** Implement `IntoResponse` for `&'static [u8; N]` and `[u8; N]` ([#1690]) - **fixed:** Make `Path` support types uses `serde::Deserializer::deserialize_any` ([#1693]) +- **added:** Implement `Clone` and `Service` for `axum::middleware::Next` ([#1712]) [#1690]: https://github.com/tokio-rs/axum/pull/1690 [#1693]: https://github.com/tokio-rs/axum/pull/1693 +[#1712]: https://github.com/tokio-rs/axum/pull/1712 # 0.6.2 (9. January, 2023) diff --git a/axum/src/middleware/from_fn.rs b/axum/src/middleware/from_fn.rs index 06ea5b12..28686504 100644 --- a/axum/src/middleware/from_fn.rs +++ b/axum/src/middleware/from_fn.rs @@ -346,6 +346,28 @@ impl fmt::Debug for Next { } } +impl Clone for Next { + fn clone(&self) -> Self { + Self { + inner: self.inner.clone(), + } + } +} + +impl Service> for Next { + type Response = Response; + type Error = Infallible; + type Future = Pin> + Send>>; + + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + self.inner.poll_ready(cx) + } + + fn call(&mut self, req: Request) -> Self::Future { + self.inner.call(req) + } +} + /// Response future for [`FromFn`]. pub struct ResponseFuture { inner: BoxFuture<'static, Response>,