From 0edd1c80ed3576705423877d6906684df261cc45 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Mon, 5 May 2025 00:00:00 +0000 Subject: [PATCH] feat(client): `TrySendError` is `From` this commit introduces a new trait implementation for `hyper::client::conn::TrySendError`. this commit allows a `TrySendError` to be constructed `From` a conventional `hyper::Error`. one example of a motivating use case for this change is that this is needed in order 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()`. thus, the `?` operator may construct a `TrySendError` from errors possibly returned by `hyper::client::conn::http2::SendRequest::poll_ready()` or `hyper::client::conn::http1::SendRequest::poll_ready()`, within a `Service` that eventually calls `try_send_request()` in the context of `Service::call()`. --- see: * https://github.com/hyperium/hyper/pull/3691 * https://docs.rs/hyper/latest/hyper/client/conn/struct.TrySendError.html * https://docs.rs/hyper/latest/hyper/struct.Error.html * https://docs.rs/hyper/latest/hyper/client/conn/http2/struct.SendRequest.html#method.try_send_request * https://docs.rs/tower/latest/tower/trait.Service.html#associatedtype.Error * https://docs.rs/hyper/latest/hyper/client/conn/http1/struct.SendRequest.html#method.poll_ready * https://docs.rs/hyper/latest/hyper/client/conn/http2/struct.SendRequest.html#method.poll_ready Signed-off-by: katelyn martin --- src/client/dispatch.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 4ae41c509d..8613d51e98 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -310,6 +310,15 @@ impl TrySendError { } } +impl From for TrySendError { + fn from(error: crate::Error) -> Self { + Self { + error, + message: None, + } + } +} + #[cfg(feature = "http2")] pin_project! { pub struct SendWhen