about summary refs log tree commit diff
diff options
context:
space:
mode:
authorksqsf <i@ksqsf.moe>2019-08-01 02:35:14 +0800
committerksqsf <i@ksqsf.moe>2019-08-01 02:35:14 +0800
commit6c130817623426697d8ebdf5d505487bd11ee2f6 (patch)
treef4d153d22fa8d758a3d7b3da53a457a218951f01
parent5a36b0dba1d7a350bba04b1abf256f057b3d1079 (diff)
downloadrust-6c130817623426697d8ebdf5d505487bd11ee2f6.tar.gz
rust-6c130817623426697d8ebdf5d505487bd11ee2f6.zip
Rename {copied,cloned} to {copied,cloned}_ok, and add {copied,cloned} to copy/clone both Ok and Err
-rw-r--r--src/libcore/result.rs144
1 files changed, 140 insertions, 4 deletions
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index 77cb447b954..0aa8fcb69b9 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -835,7 +835,7 @@ impl<T: Copy, E> Result<&T, E> {
     /// assert_eq!(copied, Ok(12));
     /// ```
     #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
-    pub fn copied(self) -> Result<T, E> {
+    pub fn copied_ok(self) -> Result<T, E> {
         self.map(|&t| t)
     }
 }
@@ -855,7 +855,7 @@ impl<T: Copy, E> Result<&mut T, E> {
     /// assert_eq!(copied, Ok(12));
     /// ```
     #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
-    pub fn copied(self) -> Result<T, E> {
+    pub fn copied_ok(self) -> Result<T, E> {
         self.map(|&mut t| t)
     }
 }
@@ -900,6 +900,74 @@ impl<T, E: Copy> Result<T, &mut E> {
     }
 }
 
+impl<T: Copy, E: Copy> Result<&T, &E> {
+    /// Maps a `Result<&T, &E>` to a `Result<T, E>` 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<T, E> {
+        self.copied_ok().copied_err()
+    }
+}
+
+impl<T: Copy, E: Copy> Result<&mut T, &E> {
+    /// Maps a `Result<&mut T, &E>` to a `Result<T, E>` 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<T, E> {
+        self.copied_ok().copied_err()
+    }
+}
+
+impl<T: Copy, E: Copy> Result<&T, &mut E> {
+    /// Maps a `Result<&T, &mut E>` to a `Result<T, E>` 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<T, E> {
+        self.copied_ok().copied_err()
+    }
+}
+
+impl<T: Copy, E: Copy> Result<&mut T, &mut E> {
+    /// Maps a `Result<&mut T, &mut E>` to a `Result<T, E>` 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<T, E> {
+        self.copied_ok().copied_err()
+    }
+}
+
 impl<T: Clone, E> Result<&T, E> {
     /// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
     /// `Ok` part.
@@ -915,7 +983,7 @@ impl<T: Clone, E> Result<&T, E> {
     /// assert_eq!(cloned, Ok(12));
     /// ```
     #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
-    pub fn cloned(self) -> Result<T, E> {
+    pub fn cloned_ok(self) -> Result<T, E> {
         self.map(|t| t.clone())
     }
 }
@@ -935,7 +1003,7 @@ impl<T: Clone, E> Result<&mut T, E> {
     /// assert_eq!(cloned, Ok(12));
     /// ```
     #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
-    pub fn cloned(self) -> Result<T, E> {
+    pub fn cloned_ok(self) -> Result<T, E> {
         self.map(|t| t.clone())
     }
 }
@@ -980,6 +1048,74 @@ impl<T, E: Clone> Result<T, &mut E> {
     }
 }
 
+impl<T: Clone, E: Clone> Result<&T, &E> {
+    /// Maps a `Result<&T, &E>` to a `Result<T, E>` 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<T, E> {
+        self.cloned_ok().cloned_err()
+    }
+}
+
+impl<T: Clone, E: Clone> Result<&mut T, &E> {
+    /// Maps a `Result<&mut T, &E>` to a `Result<T, E>` 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<T, E> {
+        self.cloned_ok().cloned_err()
+    }
+}
+
+impl<T: Clone, E: Clone> Result<&T, &mut E> {
+    /// Maps a `Result<&T, &mut E>` to a `Result<T, E>` 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<T, E> {
+        self.cloned_ok().cloned_err()
+    }
+}
+
+impl<T: Clone, E: Clone> Result<&mut T, &mut E> {
+    /// Maps a `Result<&mut T, &mut E>` to a `Result<T, E>` 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<T, E> {
+        self.cloned_ok().cloned_err()
+    }
+}
+
 impl<T, E: fmt::Debug> Result<T, E> {
     /// Unwraps a result, yielding the content of an [`Ok`].
     ///