sync: add std error impl for broadcast errors (#2141)

This commit is contained in:
Lucio Franco
2020-01-21 11:25:05 -08:00
committed by Carl Lerche
parent c7719a2d29
commit 0bb17300f7
+23
View File
@@ -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 {}