Make reason for try_send errors clearer (#864)

This commit is contained in:
Jon Gjengset
2019-01-23 15:06:24 -08:00
committed by Carl Lerche
parent c6f8bdb249
commit 0ec8986b0b
3 changed files with 33 additions and 2 deletions
+18
View File
@@ -239,6 +239,24 @@ impl<T> TrySendError<T> {
pub fn into_inner(self) -> T {
self.value
}
/// Did the send fail because the channel has been closed?
pub fn is_closed(&self) -> bool {
if let ErrorKind::Closed = self.kind {
true
} else {
false
}
}
/// Did the send fail because the channel was at capacity?
pub fn is_full(&self) -> bool {
if let ErrorKind::NoCapacity = self.kind {
true
} else {
false
}
}
}
impl<T: fmt::Debug> fmt::Display for TrySendError<T> {
+1 -1
View File
@@ -48,7 +48,7 @@ impl<T> fmt::Debug for UnboundedReceiver<T> {
#[derive(Debug)]
pub struct UnboundedSendError(());
/// Error returned by `UnboundedSender::try_send`.
/// Returned by `UnboundedSender::try_send` when the channel has been closed.
#[derive(Debug)]
pub struct UnboundedTrySendError<T>(T);