diff options
author | Lucio Franco <luciofranco14@gmail.com> | 2020-01-21 14:25:05 -0500 |
---|---|---|
committer | Carl Lerche <me@carllerche.com> | 2020-01-21 11:25:05 -0800 |
commit | 0bb17300f70ef74e335f4ada65706872451603b3 (patch) | |
tree | 37ce503600057f1b31f07faa0b878ee53233afde /tokio/src | |
parent | c7719a2d2962f83854193b4c9131ee275a5a4475 (diff) |
sync: add std error impl for broadcast errors (#2141)
Diffstat (limited to 'tokio/src')
-rw-r--r-- | tokio/src/sync/broadcast.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tokio/src/sync/broadcast.rs b/tokio/src/sync/broadcast.rs index f915da6c..e020a3c3 100644 --- a/tokio/src/sync/broadcast.rs +++ b/tokio/src/sync/broadcast.rs @@ -1005,3 +1005,26 @@ fn ok_empty<T>(res: Result<T, TryRecvError>) -> Result<Option<T>, 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 {} |