From 5e7113639d0f945bfe8c6c45a45eda3c9c5a52bf Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Tue, 29 Jul 2025 00:00:00 +0000 Subject: [PATCH] feat(client/dispatch): `TrySendError: std::error::Error` this commit introduces a `std::error::Error` implementation for `hyper::client::conn::TrySendError`. this allows callers of `hyper::client::conn::http2::SendRequest::try_send_request()` or `hyper::client::conn::http1::SendRequest::try_send_request()` to box a `TrySendError` without discarding a potentially recovered message. a `std::fmt::Display` implementation is added in this commit, because it is a prerequisite for implementations of `std::error::Error`. for some previous discussion on this topic, see "_other options_" here: https://github.com/hyperium/hyper/pull/3883#issuecomment-2860212062. Ref: https://github.com/hyperium/hyper/pull/3883 Ref: https://github.com/hyperium/hyper/pull/3892 Signed-off-by: katelyn martin --- src/client/dispatch.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs index 412f7af52c..efbf9f0e9c 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -1,3 +1,5 @@ +use std::error::Error as StdError; +use std::fmt; use std::task::{Context, Poll}; #[cfg(feature = "http2")] use std::{future::Future, pin::Pin}; @@ -323,6 +325,22 @@ impl TrySendError { } } +impl fmt::Display for TrySendError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { error, message: _ } = self; + write!(f, "{}", error) + } +} + +impl StdError for TrySendError +where + T: std::fmt::Debug, +{ + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + Some(&self.error) + } +} + #[cfg(feature = "http2")] pin_project! { pub struct SendWhen