From a491b16a89f6df83efaf8d00de0786d6aeaec6b7 Mon Sep 17 00:00:00 2001 From: "Caleb Leinz (he/him)" <103841857+cmleinz@users.noreply.github.com> Date: Wed, 7 Aug 2024 15:06:37 -0700 Subject: [PATCH] sync: add `{TrySendError,SendTimeoutError}::into_inner` (#6755) --- tokio/src/sync/mpsc/error.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tokio/src/sync/mpsc/error.rs b/tokio/src/sync/mpsc/error.rs index 2fc24b38d..9fef7fd9c 100644 --- a/tokio/src/sync/mpsc/error.rs +++ b/tokio/src/sync/mpsc/error.rs @@ -36,6 +36,16 @@ pub enum TrySendError { Closed(T), } +impl TrySendError { + /// Consume the `TrySendError`, returning the unsent value. + pub fn into_inner(self) -> T { + match self { + TrySendError::Full(val) => val, + TrySendError::Closed(val) => val, + } + } +} + impl fmt::Debug for TrySendError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { @@ -123,6 +133,16 @@ cfg_time! { Closed(T), } + impl SendTimeoutError { + /// Consume the `SendTimeoutError`, returning the unsent value. + pub fn into_inner(self) -> T { + match self { + SendTimeoutError::Timeout(val) => val, + SendTimeoutError::Closed(val) => val, + } + } + } + impl fmt::Debug for SendTimeoutError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self {