Skip to content

Commit 5e71136

Browse files
committed
feat(client/dispatch): TrySendError<T>: 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<T>` 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: hyperium#3883 (comment). Ref: hyperium#3883 Ref: hyperium#3892 Signed-off-by: katelyn martin <[email protected]>
1 parent 974289f commit 5e71136

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/client/dispatch.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::error::Error as StdError;
2+
use std::fmt;
13
use std::task::{Context, Poll};
24
#[cfg(feature = "http2")]
35
use std::{future::Future, pin::Pin};
@@ -323,6 +325,22 @@ impl<T> TrySendError<T> {
323325
}
324326
}
325327

328+
impl<T> fmt::Display for TrySendError<T> {
329+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
330+
let Self { error, message: _ } = self;
331+
write!(f, "{}", error)
332+
}
333+
}
334+
335+
impl<T> StdError for TrySendError<T>
336+
where
337+
T: std::fmt::Debug,
338+
{
339+
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
340+
Some(&self.error)
341+
}
342+
}
343+
326344
#[cfg(feature = "http2")]
327345
pin_project! {
328346
pub struct SendWhen<B>

0 commit comments

Comments
 (0)