Skip to content

Implement std::error::Error for std::sync::mpsc error types #23125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@
use prelude::v1::*;

use sync::Arc;
use error;
use fmt;
use mem;
use cell::UnsafeCell;
Expand Down Expand Up @@ -975,6 +976,18 @@ impl<T> fmt::Display for SendError<T> {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> error::Error for SendError<T> {

fn description(&self) -> &str {
"sending on a closed channel"
}

fn cause(&self) -> Option<&error::Error> {
None
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> fmt::Debug for TrySendError<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -999,13 +1012,44 @@ impl<T> fmt::Display for TrySendError<T> {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> error::Error for TrySendError<T> {

fn description(&self) -> &str {
match *self {
TrySendError::Full(..) => {
"sending on a full channel"
}
TrySendError::Disconnected(..) => {
"sending on a closed channel"
}
}
}

fn cause(&self) -> Option<&error::Error> {
None
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for RecvError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
"receiving on a closed channel".fmt(f)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl error::Error for RecvError {

fn description(&self) -> &str {
"receiving on a closed channel"
}

fn cause(&self) -> Option<&error::Error> {
None
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for TryRecvError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand All @@ -1020,6 +1064,25 @@ impl fmt::Display for TryRecvError {
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl error::Error for TryRecvError {

fn description(&self) -> &str {
match *self {
TryRecvError::Empty => {
"receiving on an empty channel"
}
TryRecvError::Disconnected => {
"receiving on a closed channel"
}
}
}

fn cause(&self) -> Option<&error::Error> {
None
}
}

#[cfg(test)]
mod test {
use prelude::v1::*;
Expand Down