Implement Clone and Service for Next (#1712)

This commit is contained in:
David Pedersen 2023-01-20 21:19:01 +01:00 committed by GitHub
parent 6d815e2b0a
commit 7a52161826
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -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)

View file

@ -346,6 +346,28 @@ impl<B> fmt::Debug for Next<B> {
}
}
impl<B> Clone for Next<B> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
}
}
}
impl<B> Service<Request<B>> for Next<B> {
type Response = Response;
type Error = Infallible;
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.inner.poll_ready(cx)
}
fn call(&mut self, req: Request<B>) -> Self::Future {
self.inner.call(req)
}
}
/// Response future for [`FromFn`].
pub struct ResponseFuture {
inner: BoxFuture<'static, Response>,