Skip to content

Commit 0edd1c8

Browse files
committed
feat(client): TrySendError<T> is From<Error>
this commit introduces a new trait implementation for `hyper::client::conn::TrySendError<T>`. this commit allows a `TrySendError<T>` 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<T>` 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<T>` from errors possibly returned by `hyper::client::conn::http2::SendRequest::poll_ready()` or `hyper::client::conn::http1::SendRequest::poll_ready()`, within a `Service<T>` that eventually calls `try_send_request()` in the context of `Service::call()`. --- see: * #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 <[email protected]>
1 parent 12d9b55 commit 0edd1c8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/client/dispatch.rs

+9
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,15 @@ impl<T> TrySendError<T> {
310310
}
311311
}
312312

313+
impl<T> From<crate::Error> for TrySendError<T> {
314+
fn from(error: crate::Error) -> Self {
315+
Self {
316+
error,
317+
message: None,
318+
}
319+
}
320+
}
321+
313322
#[cfg(feature = "http2")]
314323
pin_project! {
315324
pub struct SendWhen<B>

0 commit comments

Comments
 (0)