From 73ed6cf7fb7696ced5b6487de1e14bced35be601 Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Mon, 23 Oct 2017 22:49:06 +0200 Subject: [PATCH 1/2] Implement From for TryRecvError and RecvTimeoutError --- src/libstd/sync/mpsc/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 45a26e594b065..b3c4d8c40a10d 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1677,6 +1677,15 @@ impl error::Error for TryRecvError { } } +#[stable(feature = "mpsc_recv_error_from", since = "1.23.0")] +impl From 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 { @@ -1709,6 +1718,15 @@ impl error::Error for RecvTimeoutError { } } +#[stable(feature = "mpsc_recv_error_from", since = "1.23.0")] +impl From for RecvTimeoutError { + fn from(err: RecvError) -> RecvTimeoutError { + match err { + RecvError => RecvTimeoutError::Disconnected, + } + } +} + #[cfg(all(test, not(target_os = "emscripten")))] mod tests { use env; From 448215d226f2946c08d01ff230570a6e3b64b1de Mon Sep 17 00:00:00 2001 From: Julien Cretin Date: Tue, 31 Oct 2017 00:18:53 +0100 Subject: [PATCH 2/2] Implement From> for TrySendError --- src/libstd/sync/mpsc/mod.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index b3c4d8c40a10d..8d7f60f9d2c03 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -1625,6 +1625,15 @@ impl error::Error for TrySendError { } } +#[stable(feature = "mpsc_error_conversions", since = "1.23.0")] +impl From> for TrySendError { + fn from(err: SendError) -> TrySendError { + 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 { @@ -1677,7 +1686,7 @@ impl error::Error for TryRecvError { } } -#[stable(feature = "mpsc_recv_error_from", since = "1.23.0")] +#[stable(feature = "mpsc_error_conversions", since = "1.23.0")] impl From for TryRecvError { fn from(err: RecvError) -> TryRecvError { match err { @@ -1718,7 +1727,7 @@ impl error::Error for RecvTimeoutError { } } -#[stable(feature = "mpsc_recv_error_from", since = "1.23.0")] +#[stable(feature = "mpsc_error_conversions", since = "1.23.0")] impl From for RecvTimeoutError { fn from(err: RecvError) -> RecvTimeoutError { match err {