From 0bb17300f70ef74e335f4ada65706872451603b3 Mon Sep 17 00:00:00 2001 From: Lucio Franco Date: Tue, 21 Jan 2020 14:25:05 -0500 Subject: [PATCH] sync: add std error impl for broadcast errors (#2141) --- tokio/src/sync/broadcast.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tokio/src/sync/broadcast.rs b/tokio/src/sync/broadcast.rs index f915da6c4..e020a3c34 100644 --- a/tokio/src/sync/broadcast.rs +++ b/tokio/src/sync/broadcast.rs @@ -1005,3 +1005,26 @@ fn ok_empty(res: Result) -> Result, RecvError> { Err(TryRecvError::Closed) => Err(RecvError::Closed), } } + +impl fmt::Display for RecvError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + RecvError::Closed => write!(f, "channel closed"), + RecvError::Lagged(amt) => write!(f, "channel lagged by {}", amt), + } + } +} + +impl std::error::Error for RecvError {} + +impl fmt::Display for TryRecvError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + TryRecvError::Empty => write!(f, "channel empty"), + TryRecvError::Closed => write!(f, "channel closed"), + TryRecvError::Lagged(amt) => write!(f, "channel lagged by {}", amt), + } + } +} + +impl std::error::Error for TryRecvError {}