From a7df8b99e77e9a2508168408c08a44aafd2c3302 Mon Sep 17 00:00:00 2001 From: katelyn martin Date: Mon, 5 May 2025 00:00:00 +0000 Subject: [PATCH] feat(client): add a `TrySendError::message()` method this commit introduces a new inherent method to `hyper::client::conn::TrySendError`. this error type includes a `TrySendError::take_message()` method today that will return an owned instance of the inbound message, should the underlying dispatch have been closed before serialization of the message ever began. this commit introduces a new method that allows callers to inspect the message, e.g. to update metrics, without needing to take ownership of the message. 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..c1744926c6 100644 --- a/src/client/dispatch.rs +++ b/src/client/dispatch.rs @@ -304,6 +304,15 @@ impl TrySendError { self.message.take() } + /// Returns a reference to the recovered message. + /// + /// The message will not always have been recovered. If an error occurs + /// after the message has been serialized onto the connection, it will not + /// be available here. + pub fn message(&self) -> Option<&T> { + self.message.as_ref() + } + /// Consumes this to return the inner error. pub fn into_error(self) -> crate::Error { self.error