Skip to content

Commit e63e268

Browse files
committed
Consolidate impl Result<&T, E>
1 parent b2df61f commit e63e268

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

library/core/src/result.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ impl<T, E> Result<T, E> {
14931493
}
14941494
}
14951495

1496-
impl<T: Copy, E> Result<&T, E> {
1496+
impl<T, E> Result<&T, E> {
14971497
/// Maps a `Result<&T, E>` to a `Result<T, E>` by copying the contents of the
14981498
/// `Ok` part.
14991499
///
@@ -1508,9 +1508,33 @@ impl<T: Copy, E> Result<&T, E> {
15081508
/// assert_eq!(copied, Ok(12));
15091509
/// ```
15101510
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
1511-
pub fn copied(self) -> Result<T, E> {
1511+
pub fn copied(self) -> Result<T, E>
1512+
where
1513+
T: Copy,
1514+
{
15121515
self.map(|&t| t)
15131516
}
1517+
1518+
/// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
1519+
/// `Ok` part.
1520+
///
1521+
/// # Examples
1522+
///
1523+
/// ```
1524+
/// #![feature(result_cloned)]
1525+
/// let val = 12;
1526+
/// let x: Result<&i32, i32> = Ok(&val);
1527+
/// assert_eq!(x, Ok(&12));
1528+
/// let cloned = x.cloned();
1529+
/// assert_eq!(cloned, Ok(12));
1530+
/// ```
1531+
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
1532+
pub fn cloned(self) -> Result<T, E>
1533+
where
1534+
T: Clone,
1535+
{
1536+
self.map(|t| t.clone())
1537+
}
15141538
}
15151539

15161540
impl<T: Copy, E> Result<&mut T, E> {
@@ -1533,26 +1557,6 @@ impl<T: Copy, E> Result<&mut T, E> {
15331557
}
15341558
}
15351559

1536-
impl<T: Clone, E> Result<&T, E> {
1537-
/// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
1538-
/// `Ok` part.
1539-
///
1540-
/// # Examples
1541-
///
1542-
/// ```
1543-
/// #![feature(result_cloned)]
1544-
/// let val = 12;
1545-
/// let x: Result<&i32, i32> = Ok(&val);
1546-
/// assert_eq!(x, Ok(&12));
1547-
/// let cloned = x.cloned();
1548-
/// assert_eq!(cloned, Ok(12));
1549-
/// ```
1550-
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
1551-
pub fn cloned(self) -> Result<T, E> {
1552-
self.map(|t| t.clone())
1553-
}
1554-
}
1555-
15561560
impl<T: Clone, E> Result<&mut T, E> {
15571561
/// Maps a `Result<&mut T, E>` to a `Result<T, E>` by cloning the contents of the
15581562
/// `Ok` part.

0 commit comments

Comments
 (0)