Skip to content
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

Implement From<RecvError> for TryRecvError and RecvTimeoutError #45506

Merged
merged 2 commits into from
Nov 28, 2017
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
27 changes: 27 additions & 0 deletions src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,15 @@ impl<T: Send> error::Error for TrySendError<T> {
}
}

#[stable(feature = "mpsc_error_conversions", since = "1.23.0")]
impl<T> From<SendError<T>> for TrySendError<T> {
fn from(err: SendError<T>) -> TrySendError<T> {
match err {
SendError(t) => TrySendError::Disconnected(t),
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl fmt::Display for RecvError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -1677,6 +1686,15 @@ impl error::Error for TryRecvError {
}
}

#[stable(feature = "mpsc_error_conversions", since = "1.23.0")]
impl From<RecvError> for TryRecvError {
fn from(err: RecvError) -> TryRecvError {
match err {
RecvError => TryRecvError::Disconnected,
}
}
}

#[stable(feature = "mpsc_recv_timeout_error", since = "1.15.0")]
impl fmt::Display for RecvTimeoutError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down Expand Up @@ -1709,6 +1727,15 @@ impl error::Error for RecvTimeoutError {
}
}

#[stable(feature = "mpsc_error_conversions", since = "1.23.0")]
impl From<RecvError> for RecvTimeoutError {
fn from(err: RecvError) -> RecvTimeoutError {
match err {
RecvError => RecvTimeoutError::Disconnected,
}
}
}

#[cfg(all(test, not(target_os = "emscripten")))]
mod tests {
use env;
Expand Down