From 98eba06ab6c49fbb0f1dfc8976f0e4653245fa98 Mon Sep 17 00:00:00 2001 From: Ell Date: Wed, 2 Apr 2025 16:55:24 +0300 Subject: [PATCH 1/3] fix(server): Enforce `serve_connection` result usage --- src/server/conn/auto/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/server/conn/auto/mod.rs b/src/server/conn/auto/mod.rs index fdc377c7..e00a9743 100644 --- a/src/server/conn/auto/mod.rs +++ b/src/server/conn/auto/mod.rs @@ -156,6 +156,7 @@ impl Builder { } /// Bind a connection together with a [`Service`]. + #[must_use] pub fn serve_connection(&self, io: I, service: S) -> Connection<'_, I, S, E> where S: Service, Response = Response>, @@ -199,6 +200,7 @@ impl Builder { /// instead. See the documentation of the latter to understand why. /// /// [`hyper_util::server::conn::auto::upgrade::downcast`]: crate::server::conn::auto::upgrade::downcast + #[must_use] pub fn serve_connection_with_upgrades( &self, io: I, From 790dc6987f0c6151af37933e0245f6c53598ac1e Mon Sep 17 00:00:00 2001 From: Ell Date: Wed, 2 Apr 2025 17:47:51 +0300 Subject: [PATCH 2/3] refactor(server): Enforce `must_use` at the type level --- src/server/conn/auto/mod.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/server/conn/auto/mod.rs b/src/server/conn/auto/mod.rs index e00a9743..f3a4ce00 100644 --- a/src/server/conn/auto/mod.rs +++ b/src/server/conn/auto/mod.rs @@ -156,7 +156,6 @@ impl Builder { } /// Bind a connection together with a [`Service`]. - #[must_use] pub fn serve_connection(&self, io: I, service: S) -> Connection<'_, I, S, E> where S: Service, Response = Response>, @@ -200,7 +199,6 @@ impl Builder { /// instead. See the documentation of the latter to understand why. /// /// [`hyper_util::server::conn::auto::upgrade::downcast`]: crate::server::conn::auto::upgrade::downcast - #[must_use] pub fn serve_connection_with_upgrades( &self, io: I, @@ -320,7 +318,12 @@ where } pin_project! { - /// Connection future. + /// A [`Future`](core::future::Future) representing an HTTP/1 connection, returned from + /// [`Builder::serve_connection`](struct.Builder.html#method.serve_connection). + /// + /// To drive HTTP on this connection this future **must be polled**, typically with + /// `.await`. If it isn't polled, no progress will be made on this connection. + #[must_use = "futures do nothing unless polled"] pub struct Connection<'a, I, S, E> where S: HttpService, @@ -492,7 +495,11 @@ where } pin_project! { - /// Connection future. + /// An future binding a connection with a Service with Upgrade support. + /// + /// To drive HTTP on this connection this future **must be polled**, typically with + /// `.await`. If it isn't polled, no progress will be made on this connection. + #[must_use = "futures do nothing unless polled"] pub struct UpgradeableConnection<'a, I, S, E> where S: HttpService, From 422c407247e8d893d1998078ff70e03e98dae597 Mon Sep 17 00:00:00 2001 From: Ell Date: Wed, 2 Apr 2025 18:02:39 +0300 Subject: [PATCH 3/3] docs(server): Improve clarity of `UpgradableConnection` documentation --- src/server/conn/auto/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/server/conn/auto/mod.rs b/src/server/conn/auto/mod.rs index f3a4ce00..30c1d160 100644 --- a/src/server/conn/auto/mod.rs +++ b/src/server/conn/auto/mod.rs @@ -495,7 +495,8 @@ where } pin_project! { - /// An future binding a connection with a Service with Upgrade support. + /// An upgradable [`Connection`], returned by + /// [`Builder::serve_upgradable_connection`](struct.Builder.html#method.serve_connection_with_upgrades). /// /// To drive HTTP on this connection this future **must be polled**, typically with /// `.await`. If it isn't polled, no progress will be made on this connection.