From a0ab5a3651f5cb30efa2f82a3ee15a7df479080a Mon Sep 17 00:00:00 2001 From: ksqsf Date: Thu, 1 Aug 2019 00:26:47 +0800 Subject: [PATCH 1/7] Add Result::cloned{,_err} and Result::copied{,_err} --- src/libcore/result.rs | 160 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 559877ddd5a1c..a8f0f422cb4d7 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -820,6 +820,166 @@ impl Result { } } +impl Result<&T, E> { + /// Maps a `Result<&T, E>` to a `Result` by copying the contents of the + /// `Ok` part. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_copied)] + /// let val = 12; + /// let x = Ok(&val); + /// assert_eq!(x, Ok(&12)); + /// let copied = x.copied(); + /// assert_eq!(copied, Ok(12)); + /// ``` + #[unstable(feature = "result_copied", reason = "newly added", issue = "XXXXX")] + fn copied(self) -> Result { + self.map(|&t| t) + } +} + +impl Result<&mut T, E> { + /// Maps a `Result<&mut T, E>` to a `Result` by copying the contents of the + /// `Ok` part. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_copied)] + /// let val = 12; + /// let x = Ok(&mut val); + /// assert_eq!(x, Ok(&mut 12)); + /// let copied = x.copied(); + /// assert_eq!(copied, Ok(12)); + /// ``` + #[unstable(feature = "result_copied", reason = "newly added", issue = "XXXXX")] + fn copied(self) -> Result { + self.map(|&mut t| t) + } +} + +impl Result { + /// Maps a `Result` to a `Result` by copying the contents of the + /// `Err` part. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_copied)] + /// let val = 12; + /// let x = Err(&val); + /// assert_eq!(x, Err(&12)); + /// let copied = x.copied_err(); + /// assert_eq!(copied, Err(12)); + /// ``` + #[unstable(feature = "result_copied", reason = "newly added", issue = "XXXXX")] + fn copied_err(self) -> Result { + self.map_err(|&e| e) + } +} + +impl Result { + /// Maps a `Result` to a `Result` by copying the contents of the + /// `Err` part. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_copied)] + /// let val = 12; + /// let x = Err(&mut val); + /// assert_eq!(x, Err(&mut 12)); + /// let copied = x.copied(); + /// assert_eq!(cloned, Err(12)); + /// ``` + #[unstable(feature = "result_copied", reason = "newly added", issue = "XXXXX")] + fn copied_err(self) -> Result { + self.map_err(|&mut e| e) + } +} + +impl Result<&T, E> { + /// Maps a `Result<&T, E>` to a `Result` by cloning the contents of the + /// `Ok` part. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_cloned)] + /// let val = 12; + /// let x = Ok(&val); + /// assert_eq!(x, Ok(&12)); + /// let cloned = x.cloned(); + /// assert_eq!(cloned, Ok(12)); + /// ``` + #[unstable(feature = "result_cloned", reason = "newly added", issue = "XXXXX")] + fn cloned(self) -> Result { + self.map(|t| t.clone()) + } +} + +impl Result<&mut T, E> { + /// Maps a `Result<&mut T, E>` to a `Result` by cloning the contents of the + /// `Ok` part. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_cloned)] + /// let val = 12; + /// let x = Ok(&mut val); + /// assert_eq!(x, Ok(&mut 12)); + /// let cloned = x.cloned(); + /// assert_eq!(cloned, Ok(12)); + /// ``` + #[unstable(feature = "result_cloned", reason = "newly added", issue = "XXXXX")] + fn cloned(self) -> Result { + self.map(|t| t.clone()) + } +} + +impl Result { + /// Maps a `Result` to a `Result` by cloning the contents of the + /// `Err` part. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_cloned)] + /// let val = 12; + /// let x = Err(&mut val); + /// assert_eq!(x, Err(&mut 12)); + /// let cloned = x.cloned(); + /// assert_eq!(cloned, Err(12)); + /// ``` + #[unstable(feature = "result_cloned", reason = "newly added", issue = "XXXXX")] + fn cloned_err(self) -> Result { + self.map_err(|e| e.clone()) + } +} + +impl Result { + /// Maps a `Result` to a `Result` by cloning the contents of the + /// `Err` part. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_cloned)] + /// let val = 12; + /// let x = Err(&mut val); + /// assert_eq!(x, Err(&mut 12)); + /// let cloned = x.cloned(); + /// assert_eq!(cloned, Err(12)); + /// ``` + #[unstable(feature = "result_cloned", reason = "newly added", issue = "XXXXX")] + fn cloned_err(self) -> Result { + self.map_err(|e| e.clone()) + } +} + impl Result { /// Unwraps a result, yielding the content of an [`Ok`]. /// From c784720f3a2d0b66142da3c9a9fd6039f5d3a036 Mon Sep 17 00:00:00 2001 From: ksqsf Date: Thu, 1 Aug 2019 00:55:36 +0800 Subject: [PATCH 2/7] Fix issue and impl --- src/libcore/result.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index a8f0f422cb4d7..31584972b9f68 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -834,7 +834,7 @@ impl Result<&T, E> { /// let copied = x.copied(); /// assert_eq!(copied, Ok(12)); /// ``` - #[unstable(feature = "result_copied", reason = "newly added", issue = "XXXXX")] + #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] fn copied(self) -> Result { self.map(|&t| t) } @@ -854,7 +854,7 @@ impl Result<&mut T, E> { /// let copied = x.copied(); /// assert_eq!(copied, Ok(12)); /// ``` - #[unstable(feature = "result_copied", reason = "newly added", issue = "XXXXX")] + #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] fn copied(self) -> Result { self.map(|&mut t| t) } @@ -874,7 +874,7 @@ impl Result { /// let copied = x.copied_err(); /// assert_eq!(copied, Err(12)); /// ``` - #[unstable(feature = "result_copied", reason = "newly added", issue = "XXXXX")] + #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] fn copied_err(self) -> Result { self.map_err(|&e| e) } @@ -894,7 +894,7 @@ impl Result { /// let copied = x.copied(); /// assert_eq!(cloned, Err(12)); /// ``` - #[unstable(feature = "result_copied", reason = "newly added", issue = "XXXXX")] + #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] fn copied_err(self) -> Result { self.map_err(|&mut e| e) } @@ -914,7 +914,7 @@ impl Result<&T, E> { /// let cloned = x.cloned(); /// assert_eq!(cloned, Ok(12)); /// ``` - #[unstable(feature = "result_cloned", reason = "newly added", issue = "XXXXX")] + #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] fn cloned(self) -> Result { self.map(|t| t.clone()) } @@ -934,13 +934,13 @@ impl Result<&mut T, E> { /// let cloned = x.cloned(); /// assert_eq!(cloned, Ok(12)); /// ``` - #[unstable(feature = "result_cloned", reason = "newly added", issue = "XXXXX")] + #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] fn cloned(self) -> Result { self.map(|t| t.clone()) } } -impl Result { +impl Result { /// Maps a `Result` to a `Result` by cloning the contents of the /// `Err` part. /// @@ -954,7 +954,7 @@ impl Result { /// let cloned = x.cloned(); /// assert_eq!(cloned, Err(12)); /// ``` - #[unstable(feature = "result_cloned", reason = "newly added", issue = "XXXXX")] + #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] fn cloned_err(self) -> Result { self.map_err(|e| e.clone()) } @@ -974,7 +974,7 @@ impl Result { /// let cloned = x.cloned(); /// assert_eq!(cloned, Err(12)); /// ``` - #[unstable(feature = "result_cloned", reason = "newly added", issue = "XXXXX")] + #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] fn cloned_err(self) -> Result { self.map_err(|e| e.clone()) } From 5a36b0dba1d7a350bba04b1abf256f057b3d1079 Mon Sep 17 00:00:00 2001 From: ksqsf Date: Thu, 1 Aug 2019 01:09:07 +0800 Subject: [PATCH 3/7] Make these methods public --- src/libcore/result.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 31584972b9f68..77cb447b95460 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -835,7 +835,7 @@ impl Result<&T, E> { /// assert_eq!(copied, Ok(12)); /// ``` #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - fn copied(self) -> Result { + pub fn copied(self) -> Result { self.map(|&t| t) } } @@ -855,7 +855,7 @@ impl Result<&mut T, E> { /// assert_eq!(copied, Ok(12)); /// ``` #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - fn copied(self) -> Result { + pub fn copied(self) -> Result { self.map(|&mut t| t) } } @@ -875,7 +875,7 @@ impl Result { /// assert_eq!(copied, Err(12)); /// ``` #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - fn copied_err(self) -> Result { + pub fn copied_err(self) -> Result { self.map_err(|&e| e) } } @@ -895,7 +895,7 @@ impl Result { /// assert_eq!(cloned, Err(12)); /// ``` #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - fn copied_err(self) -> Result { + pub fn copied_err(self) -> Result { self.map_err(|&mut e| e) } } @@ -915,7 +915,7 @@ impl Result<&T, E> { /// assert_eq!(cloned, Ok(12)); /// ``` #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - fn cloned(self) -> Result { + pub fn cloned(self) -> Result { self.map(|t| t.clone()) } } @@ -935,7 +935,7 @@ impl Result<&mut T, E> { /// assert_eq!(cloned, Ok(12)); /// ``` #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - fn cloned(self) -> Result { + pub fn cloned(self) -> Result { self.map(|t| t.clone()) } } @@ -955,7 +955,7 @@ impl Result { /// assert_eq!(cloned, Err(12)); /// ``` #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - fn cloned_err(self) -> Result { + pub fn cloned_err(self) -> Result { self.map_err(|e| e.clone()) } } @@ -975,7 +975,7 @@ impl Result { /// assert_eq!(cloned, Err(12)); /// ``` #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - fn cloned_err(self) -> Result { + pub fn cloned_err(self) -> Result { self.map_err(|e| e.clone()) } } From 6c130817623426697d8ebdf5d505487bd11ee2f6 Mon Sep 17 00:00:00 2001 From: ksqsf Date: Thu, 1 Aug 2019 02:35:14 +0800 Subject: [PATCH 4/7] Rename {copied,cloned} to {copied,cloned}_ok, and add {copied,cloned} to copy/clone both Ok and Err --- src/libcore/result.rs | 144 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 140 insertions(+), 4 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 77cb447b95460..0aa8fcb69b9c6 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -835,7 +835,7 @@ impl Result<&T, E> { /// assert_eq!(copied, Ok(12)); /// ``` #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - pub fn copied(self) -> Result { + pub fn copied_ok(self) -> Result { self.map(|&t| t) } } @@ -855,7 +855,7 @@ impl Result<&mut T, E> { /// assert_eq!(copied, Ok(12)); /// ``` #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - pub fn copied(self) -> Result { + pub fn copied_ok(self) -> Result { self.map(|&mut t| t) } } @@ -900,6 +900,74 @@ impl Result { } } +impl Result<&T, &E> { + /// Maps a `Result<&T, &E>` to a `Result` by copying the + /// contents of the result. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_copied)] + /// assert_eq!(Err(&1), Err(1)); + /// assert_eq!(Ok(&42), Ok(42)); + /// ``` + #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] + pub fn copied(self) -> Result { + self.copied_ok().copied_err() + } +} + +impl Result<&mut T, &E> { + /// Maps a `Result<&mut T, &E>` to a `Result` by copying the + /// contents of the result. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_copied)] + /// assert_eq!(Err(&1), Err(1)); + /// assert_eq!(Ok(&mut 42), Ok(42)); + /// ``` + #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] + pub fn copied(self) -> Result { + self.copied_ok().copied_err() + } +} + +impl Result<&T, &mut E> { + /// Maps a `Result<&T, &mut E>` to a `Result` by copying the + /// contents of the result. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_copied)] + /// assert_eq!(Err(&mut 1), Err(1)); + /// assert_eq!(Ok(&42), Ok(42)); + /// ``` + #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] + pub fn copied(self) -> Result { + self.copied_ok().copied_err() + } +} + +impl Result<&mut T, &mut E> { + /// Maps a `Result<&mut T, &mut E>` to a `Result` by copying + /// the contents of the result. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_copied)] + /// assert_eq!(Err(&mut 1), Err(1)); + /// assert_eq!(Ok(&mut 42), Ok(42)); + /// ``` + #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] + pub fn copied(self) -> Result { + self.copied_ok().copied_err() + } +} + impl Result<&T, E> { /// Maps a `Result<&T, E>` to a `Result` by cloning the contents of the /// `Ok` part. @@ -915,7 +983,7 @@ impl Result<&T, E> { /// assert_eq!(cloned, Ok(12)); /// ``` #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - pub fn cloned(self) -> Result { + pub fn cloned_ok(self) -> Result { self.map(|t| t.clone()) } } @@ -935,7 +1003,7 @@ impl Result<&mut T, E> { /// assert_eq!(cloned, Ok(12)); /// ``` #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - pub fn cloned(self) -> Result { + pub fn cloned_ok(self) -> Result { self.map(|t| t.clone()) } } @@ -980,6 +1048,74 @@ impl Result { } } +impl Result<&T, &E> { + /// Maps a `Result<&T, &E>` to a `Result` by cloning the contents of the + /// result. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_cloned)] + /// assert_eq!(Err(&1).cloned(), Err(1)); + /// assert_eq!(Ok(&42).cloned(), Ok(42)); + /// ``` + #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] + pub fn cloned(self) -> Result { + self.cloned_ok().cloned_err() + } +} + +impl Result<&mut T, &E> { + /// Maps a `Result<&mut T, &E>` to a `Result` by cloning the + /// contents of the result. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_cloned)] + /// assert_eq!(Err(&1).cloned(), Err(1)); + /// assert_eq!(Ok(&mut 42).cloned(), Ok(42)); + /// ``` + #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] + pub fn cloned(self) -> Result { + self.cloned_ok().cloned_err() + } +} + +impl Result<&T, &mut E> { + /// Maps a `Result<&T, &mut E>` to a `Result` by cloning the + /// contents of the result. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_cloned)] + /// assert_eq!(Err(&mut 1).cloned(), Err(1)); + /// assert_eq!(Ok(&42).cloned(), Ok(42)); + /// ``` + #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] + pub fn cloned(self) -> Result { + self.cloned_ok().cloned_err() + } +} + +impl Result<&mut T, &mut E> { + /// Maps a `Result<&mut T, &mut E>` to a `Result` by cloning + /// the contents of the result. + /// + /// # Examples + /// + /// ``` + /// #![feature(result_cloned)] + /// assert_eq!(Err(&mut 1).cloned(), Err(1)); + /// assert_eq!(Ok(&mut 42).cloned(), Ok(42)); + /// ``` + #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] + pub fn cloned(self) -> Result { + self.cloned_ok().cloned_err() + } +} + impl Result { /// Unwraps a result, yielding the content of an [`Ok`]. /// From 4b2f598986e135f0eb070a9be87a5a963e8ff3d4 Mon Sep 17 00:00:00 2001 From: ksqsf Date: Thu, 1 Aug 2019 13:38:23 +0800 Subject: [PATCH 5/7] Revert "cloned/copied" This reverts commit 6c130817623426697d8ebdf5d505487bd11ee2f6. --- src/libcore/result.rs | 144 ++---------------------------------------- 1 file changed, 4 insertions(+), 140 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 0aa8fcb69b9c6..77cb447b95460 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -835,7 +835,7 @@ impl Result<&T, E> { /// assert_eq!(copied, Ok(12)); /// ``` #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - pub fn copied_ok(self) -> Result { + pub fn copied(self) -> Result { self.map(|&t| t) } } @@ -855,7 +855,7 @@ impl Result<&mut T, E> { /// assert_eq!(copied, Ok(12)); /// ``` #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - pub fn copied_ok(self) -> Result { + pub fn copied(self) -> Result { self.map(|&mut t| t) } } @@ -900,74 +900,6 @@ impl Result { } } -impl Result<&T, &E> { - /// Maps a `Result<&T, &E>` to a `Result` by copying the - /// contents of the result. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_copied)] - /// assert_eq!(Err(&1), Err(1)); - /// assert_eq!(Ok(&42), Ok(42)); - /// ``` - #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - pub fn copied(self) -> Result { - self.copied_ok().copied_err() - } -} - -impl Result<&mut T, &E> { - /// Maps a `Result<&mut T, &E>` to a `Result` by copying the - /// contents of the result. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_copied)] - /// assert_eq!(Err(&1), Err(1)); - /// assert_eq!(Ok(&mut 42), Ok(42)); - /// ``` - #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - pub fn copied(self) -> Result { - self.copied_ok().copied_err() - } -} - -impl Result<&T, &mut E> { - /// Maps a `Result<&T, &mut E>` to a `Result` by copying the - /// contents of the result. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_copied)] - /// assert_eq!(Err(&mut 1), Err(1)); - /// assert_eq!(Ok(&42), Ok(42)); - /// ``` - #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - pub fn copied(self) -> Result { - self.copied_ok().copied_err() - } -} - -impl Result<&mut T, &mut E> { - /// Maps a `Result<&mut T, &mut E>` to a `Result` by copying - /// the contents of the result. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_copied)] - /// assert_eq!(Err(&mut 1), Err(1)); - /// assert_eq!(Ok(&mut 42), Ok(42)); - /// ``` - #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - pub fn copied(self) -> Result { - self.copied_ok().copied_err() - } -} - impl Result<&T, E> { /// Maps a `Result<&T, E>` to a `Result` by cloning the contents of the /// `Ok` part. @@ -983,7 +915,7 @@ impl Result<&T, E> { /// assert_eq!(cloned, Ok(12)); /// ``` #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - pub fn cloned_ok(self) -> Result { + pub fn cloned(self) -> Result { self.map(|t| t.clone()) } } @@ -1003,7 +935,7 @@ impl Result<&mut T, E> { /// assert_eq!(cloned, Ok(12)); /// ``` #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - pub fn cloned_ok(self) -> Result { + pub fn cloned(self) -> Result { self.map(|t| t.clone()) } } @@ -1048,74 +980,6 @@ impl Result { } } -impl Result<&T, &E> { - /// Maps a `Result<&T, &E>` to a `Result` by cloning the contents of the - /// result. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_cloned)] - /// assert_eq!(Err(&1).cloned(), Err(1)); - /// assert_eq!(Ok(&42).cloned(), Ok(42)); - /// ``` - #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - pub fn cloned(self) -> Result { - self.cloned_ok().cloned_err() - } -} - -impl Result<&mut T, &E> { - /// Maps a `Result<&mut T, &E>` to a `Result` by cloning the - /// contents of the result. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_cloned)] - /// assert_eq!(Err(&1).cloned(), Err(1)); - /// assert_eq!(Ok(&mut 42).cloned(), Ok(42)); - /// ``` - #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - pub fn cloned(self) -> Result { - self.cloned_ok().cloned_err() - } -} - -impl Result<&T, &mut E> { - /// Maps a `Result<&T, &mut E>` to a `Result` by cloning the - /// contents of the result. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_cloned)] - /// assert_eq!(Err(&mut 1).cloned(), Err(1)); - /// assert_eq!(Ok(&42).cloned(), Ok(42)); - /// ``` - #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - pub fn cloned(self) -> Result { - self.cloned_ok().cloned_err() - } -} - -impl Result<&mut T, &mut E> { - /// Maps a `Result<&mut T, &mut E>` to a `Result` by cloning - /// the contents of the result. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_cloned)] - /// assert_eq!(Err(&mut 1).cloned(), Err(1)); - /// assert_eq!(Ok(&mut 42).cloned(), Ok(42)); - /// ``` - #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - pub fn cloned(self) -> Result { - self.cloned_ok().cloned_err() - } -} - impl Result { /// Unwraps a result, yielding the content of an [`Ok`]. /// From 9733f0d16382c728e502c3efb4f38a19270f8202 Mon Sep 17 00:00:00 2001 From: ksqsf Date: Thu, 1 Aug 2019 17:12:13 +0800 Subject: [PATCH 6/7] Fix doc tests --- src/libcore/result.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 77cb447b95460..7b9f6d9ff8a61 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -829,7 +829,7 @@ impl Result<&T, E> { /// ``` /// #![feature(result_copied)] /// let val = 12; - /// let x = Ok(&val); + /// let x: Result<&i32, i32> = Ok(&val); /// assert_eq!(x, Ok(&12)); /// let copied = x.copied(); /// assert_eq!(copied, Ok(12)); @@ -848,8 +848,8 @@ impl Result<&mut T, E> { /// /// ``` /// #![feature(result_copied)] - /// let val = 12; - /// let x = Ok(&mut val); + /// let mut val = 12; + /// let x: Result<&mut i32, i32> = Ok(&mut val); /// assert_eq!(x, Ok(&mut 12)); /// let copied = x.copied(); /// assert_eq!(copied, Ok(12)); @@ -869,7 +869,7 @@ impl Result { /// ``` /// #![feature(result_copied)] /// let val = 12; - /// let x = Err(&val); + /// let x: Result = Err(&val); /// assert_eq!(x, Err(&12)); /// let copied = x.copied_err(); /// assert_eq!(copied, Err(12)); @@ -888,11 +888,11 @@ impl Result { /// /// ``` /// #![feature(result_copied)] - /// let val = 12; - /// let x = Err(&mut val); + /// let mut val = 12; + /// let x: Result = Err(&mut val); /// assert_eq!(x, Err(&mut 12)); - /// let copied = x.copied(); - /// assert_eq!(cloned, Err(12)); + /// let copied = x.copied_err(); + /// assert_eq!(copied, Err(12)); /// ``` #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] pub fn copied_err(self) -> Result { @@ -909,7 +909,7 @@ impl Result<&T, E> { /// ``` /// #![feature(result_cloned)] /// let val = 12; - /// let x = Ok(&val); + /// let x: Result<&i32, i32> = Ok(&val); /// assert_eq!(x, Ok(&12)); /// let cloned = x.cloned(); /// assert_eq!(cloned, Ok(12)); @@ -928,8 +928,8 @@ impl Result<&mut T, E> { /// /// ``` /// #![feature(result_cloned)] - /// let val = 12; - /// let x = Ok(&mut val); + /// let mut val = 12; + /// let x: Result<&mut i32, i32> = Ok(&mut val); /// assert_eq!(x, Ok(&mut 12)); /// let cloned = x.cloned(); /// assert_eq!(cloned, Ok(12)); @@ -949,9 +949,9 @@ impl Result { /// ``` /// #![feature(result_cloned)] /// let val = 12; - /// let x = Err(&mut val); - /// assert_eq!(x, Err(&mut 12)); - /// let cloned = x.cloned(); + /// let x: Result = Err(&val); + /// assert_eq!(x, Err(&12)); + /// let cloned = x.cloned_err(); /// assert_eq!(cloned, Err(12)); /// ``` #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] @@ -968,10 +968,10 @@ impl Result { /// /// ``` /// #![feature(result_cloned)] - /// let val = 12; - /// let x = Err(&mut val); + /// let mut val = 12; + /// let x: Result = Err(&mut val); /// assert_eq!(x, Err(&mut 12)); - /// let cloned = x.cloned(); + /// let cloned = x.cloned_err(); /// assert_eq!(cloned, Err(12)); /// ``` #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] From 61e52866352339326600fe694e92373f2e07fd79 Mon Sep 17 00:00:00 2001 From: ksqsf Date: Fri, 2 Aug 2019 13:58:55 +0800 Subject: [PATCH 7/7] Remove Err variants of cloned and copied --- src/libcore/result.rs | 79 ------------------------------------------- 1 file changed, 79 deletions(-) diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 7b9f6d9ff8a61..935e48574fdf5 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -860,46 +860,6 @@ impl Result<&mut T, E> { } } -impl Result { - /// Maps a `Result` to a `Result` by copying the contents of the - /// `Err` part. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_copied)] - /// let val = 12; - /// let x: Result = Err(&val); - /// assert_eq!(x, Err(&12)); - /// let copied = x.copied_err(); - /// assert_eq!(copied, Err(12)); - /// ``` - #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - pub fn copied_err(self) -> Result { - self.map_err(|&e| e) - } -} - -impl Result { - /// Maps a `Result` to a `Result` by copying the contents of the - /// `Err` part. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_copied)] - /// let mut val = 12; - /// let x: Result = Err(&mut val); - /// assert_eq!(x, Err(&mut 12)); - /// let copied = x.copied_err(); - /// assert_eq!(copied, Err(12)); - /// ``` - #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] - pub fn copied_err(self) -> Result { - self.map_err(|&mut e| e) - } -} - impl Result<&T, E> { /// Maps a `Result<&T, E>` to a `Result` by cloning the contents of the /// `Ok` part. @@ -940,45 +900,6 @@ impl Result<&mut T, E> { } } -impl Result { - /// Maps a `Result` to a `Result` by cloning the contents of the - /// `Err` part. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_cloned)] - /// let val = 12; - /// let x: Result = Err(&val); - /// assert_eq!(x, Err(&12)); - /// let cloned = x.cloned_err(); - /// assert_eq!(cloned, Err(12)); - /// ``` - #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - pub fn cloned_err(self) -> Result { - self.map_err(|e| e.clone()) - } -} - -impl Result { - /// Maps a `Result` to a `Result` by cloning the contents of the - /// `Err` part. - /// - /// # Examples - /// - /// ``` - /// #![feature(result_cloned)] - /// let mut val = 12; - /// let x: Result = Err(&mut val); - /// assert_eq!(x, Err(&mut 12)); - /// let cloned = x.cloned_err(); - /// assert_eq!(cloned, Err(12)); - /// ``` - #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] - pub fn cloned_err(self) -> Result { - self.map_err(|e| e.clone()) - } -} impl Result { /// Unwraps a result, yielding the content of an [`Ok`].