Consolidate impl Result<&mut T, E>

This commit is contained in:
David Tolnay 2021-12-30 10:31:26 -08:00
parent e63e2680da
commit b7a0ab18f6
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
1 changed files with 9 additions and 5 deletions

View File

@ -1537,7 +1537,7 @@ impl<T, E> Result<&T, E> {
} }
} }
impl<T: Copy, E> Result<&mut T, E> { impl<T, E> Result<&mut T, E> {
/// Maps a `Result<&mut T, E>` to a `Result<T, E>` by copying the contents of the /// Maps a `Result<&mut T, E>` to a `Result<T, E>` by copying the contents of the
/// `Ok` part. /// `Ok` part.
/// ///
@ -1552,12 +1552,13 @@ impl<T: Copy, E> Result<&mut T, E> {
/// assert_eq!(copied, Ok(12)); /// assert_eq!(copied, Ok(12));
/// ``` /// ```
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] #[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
pub fn copied(self) -> Result<T, E> { pub fn copied(self) -> Result<T, E>
where
T: Copy,
{
self.map(|&mut t| t) self.map(|&mut t| t)
} }
}
impl<T: Clone, E> Result<&mut T, E> {
/// Maps a `Result<&mut T, E>` to a `Result<T, E>` by cloning the contents of the /// Maps a `Result<&mut T, E>` to a `Result<T, E>` by cloning the contents of the
/// `Ok` part. /// `Ok` part.
/// ///
@ -1572,7 +1573,10 @@ impl<T: Clone, E> Result<&mut T, E> {
/// assert_eq!(cloned, Ok(12)); /// assert_eq!(cloned, Ok(12));
/// ``` /// ```
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")] #[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
pub fn cloned(self) -> Result<T, E> { pub fn cloned(self) -> Result<T, E>
where
T: Clone,
{
self.map(|t| t.clone()) self.map(|t| t.clone())
} }
} }