From cfdb07b4d4767b80023e9b1511ed4d7bcc8526a4 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Thu, 22 May 2025 00:00:00 +0000 Subject: [PATCH] feat(client/dispatch): `try_poll_ready()` methods this change is motivated by aiming to use interfaces like `hyper::client::conn::http2::SendRequest::try_send_request()` or `hyper::client::conn::http1::SendRequest::try_send_request()` in the context of tower middleware; the `Service` trait's signature is such that the same error type be returned from `Service::poll_ready()` and `Service::call()`. this means that services that might resolve to a recovered message may call `try_poll_ready` when polling for readiness. this avoids making `TrySendError` constructable externally, see #3883 as an alternate approach that was considered. Signed-off-by: katelyn martin --- src/client/dispatch.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 412f7af52c..15bef5b630 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -323,6 +323,36 @@ impl TrySendError { } } +impl crate::client::conn::http1::SendRequest { + /// Polls to determine whether this sender can be used yet for a request. + /// + /// If the associated connection is closed, this returns a [`TrySendError`]. + pub fn try_poll_ready( + &mut self, + cx: &mut Context<'_>, + ) -> Poll>>> { + self.poll_ready(cx).map_err(|error| TrySendError { + error, + message: None, + }) + } +} + +impl crate::client::conn::http2::SendRequest { + /// Polls to determine whether this sender can be used yet for a request. + /// + /// If the associated connection is closed, this returns a [`TrySendError`]. + pub fn try_poll_ready( + &mut self, + cx: &mut Context<'_>, + ) -> Poll>>> { + self.poll_ready(cx).map_err(|error| TrySendError { + error, + message: None, + }) + } +} + #[cfg(feature = "http2")] pin_project! { pub struct SendWhen