Skip to content

Commit 6c13081

Browse files
committed
Rename {copied,cloned} to {copied,cloned}_ok, and add {copied,cloned} to copy/clone both Ok and Err
1 parent 5a36b0d commit 6c13081

File tree

1 file changed

+140
-4
lines changed

1 file changed

+140
-4
lines changed

src/libcore/result.rs

+140-4
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ impl<T: Copy, E> Result<&T, E> {
835835
/// assert_eq!(copied, Ok(12));
836836
/// ```
837837
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
838-
pub fn copied(self) -> Result<T, E> {
838+
pub fn copied_ok(self) -> Result<T, E> {
839839
self.map(|&t| t)
840840
}
841841
}
@@ -855,7 +855,7 @@ impl<T: Copy, E> Result<&mut T, E> {
855855
/// assert_eq!(copied, Ok(12));
856856
/// ```
857857
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
858-
pub fn copied(self) -> Result<T, E> {
858+
pub fn copied_ok(self) -> Result<T, E> {
859859
self.map(|&mut t| t)
860860
}
861861
}
@@ -900,6 +900,74 @@ impl<T, E: Copy> Result<T, &mut E> {
900900
}
901901
}
902902

903+
impl<T: Copy, E: Copy> Result<&T, &E> {
904+
/// Maps a `Result<&T, &E>` to a `Result<T, E>` by copying the
905+
/// contents of the result.
906+
///
907+
/// # Examples
908+
///
909+
/// ```
910+
/// #![feature(result_copied)]
911+
/// assert_eq!(Err(&1), Err(1));
912+
/// assert_eq!(Ok(&42), Ok(42));
913+
/// ```
914+
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
915+
pub fn copied(self) -> Result<T, E> {
916+
self.copied_ok().copied_err()
917+
}
918+
}
919+
920+
impl<T: Copy, E: Copy> Result<&mut T, &E> {
921+
/// Maps a `Result<&mut T, &E>` to a `Result<T, E>` by copying the
922+
/// contents of the result.
923+
///
924+
/// # Examples
925+
///
926+
/// ```
927+
/// #![feature(result_copied)]
928+
/// assert_eq!(Err(&1), Err(1));
929+
/// assert_eq!(Ok(&mut 42), Ok(42));
930+
/// ```
931+
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
932+
pub fn copied(self) -> Result<T, E> {
933+
self.copied_ok().copied_err()
934+
}
935+
}
936+
937+
impl<T: Copy, E: Copy> Result<&T, &mut E> {
938+
/// Maps a `Result<&T, &mut E>` to a `Result<T, E>` by copying the
939+
/// contents of the result.
940+
///
941+
/// # Examples
942+
///
943+
/// ```
944+
/// #![feature(result_copied)]
945+
/// assert_eq!(Err(&mut 1), Err(1));
946+
/// assert_eq!(Ok(&42), Ok(42));
947+
/// ```
948+
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
949+
pub fn copied(self) -> Result<T, E> {
950+
self.copied_ok().copied_err()
951+
}
952+
}
953+
954+
impl<T: Copy, E: Copy> Result<&mut T, &mut E> {
955+
/// Maps a `Result<&mut T, &mut E>` to a `Result<T, E>` by copying
956+
/// the contents of the result.
957+
///
958+
/// # Examples
959+
///
960+
/// ```
961+
/// #![feature(result_copied)]
962+
/// assert_eq!(Err(&mut 1), Err(1));
963+
/// assert_eq!(Ok(&mut 42), Ok(42));
964+
/// ```
965+
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")]
966+
pub fn copied(self) -> Result<T, E> {
967+
self.copied_ok().copied_err()
968+
}
969+
}
970+
903971
impl<T: Clone, E> Result<&T, E> {
904972
/// Maps a `Result<&T, E>` to a `Result<T, E>` by cloning the contents of the
905973
/// `Ok` part.
@@ -915,7 +983,7 @@ impl<T: Clone, E> Result<&T, E> {
915983
/// assert_eq!(cloned, Ok(12));
916984
/// ```
917985
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
918-
pub fn cloned(self) -> Result<T, E> {
986+
pub fn cloned_ok(self) -> Result<T, E> {
919987
self.map(|t| t.clone())
920988
}
921989
}
@@ -935,7 +1003,7 @@ impl<T: Clone, E> Result<&mut T, E> {
9351003
/// assert_eq!(cloned, Ok(12));
9361004
/// ```
9371005
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
938-
pub fn cloned(self) -> Result<T, E> {
1006+
pub fn cloned_ok(self) -> Result<T, E> {
9391007
self.map(|t| t.clone())
9401008
}
9411009
}
@@ -980,6 +1048,74 @@ impl<T, E: Clone> Result<T, &mut E> {
9801048
}
9811049
}
9821050

1051+
impl<T: Clone, E: Clone> Result<&T, &E> {
1052+
/// Maps a `Result<&T, &E>` to a `Result<T, E>` by cloning the contents of the
1053+
/// result.
1054+
///
1055+
/// # Examples
1056+
///
1057+
/// ```
1058+
/// #![feature(result_cloned)]
1059+
/// assert_eq!(Err(&1).cloned(), Err(1));
1060+
/// assert_eq!(Ok(&42).cloned(), Ok(42));
1061+
/// ```
1062+
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
1063+
pub fn cloned(self) -> Result<T, E> {
1064+
self.cloned_ok().cloned_err()
1065+
}
1066+
}
1067+
1068+
impl<T: Clone, E: Clone> Result<&mut T, &E> {
1069+
/// Maps a `Result<&mut T, &E>` to a `Result<T, E>` by cloning the
1070+
/// contents of the result.
1071+
///
1072+
/// # Examples
1073+
///
1074+
/// ```
1075+
/// #![feature(result_cloned)]
1076+
/// assert_eq!(Err(&1).cloned(), Err(1));
1077+
/// assert_eq!(Ok(&mut 42).cloned(), Ok(42));
1078+
/// ```
1079+
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
1080+
pub fn cloned(self) -> Result<T, E> {
1081+
self.cloned_ok().cloned_err()
1082+
}
1083+
}
1084+
1085+
impl<T: Clone, E: Clone> Result<&T, &mut E> {
1086+
/// Maps a `Result<&T, &mut E>` to a `Result<T, E>` by cloning the
1087+
/// contents of the result.
1088+
///
1089+
/// # Examples
1090+
///
1091+
/// ```
1092+
/// #![feature(result_cloned)]
1093+
/// assert_eq!(Err(&mut 1).cloned(), Err(1));
1094+
/// assert_eq!(Ok(&42).cloned(), Ok(42));
1095+
/// ```
1096+
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
1097+
pub fn cloned(self) -> Result<T, E> {
1098+
self.cloned_ok().cloned_err()
1099+
}
1100+
}
1101+
1102+
impl<T: Clone, E: Clone> Result<&mut T, &mut E> {
1103+
/// Maps a `Result<&mut T, &mut E>` to a `Result<T, E>` by cloning
1104+
/// the contents of the result.
1105+
///
1106+
/// # Examples
1107+
///
1108+
/// ```
1109+
/// #![feature(result_cloned)]
1110+
/// assert_eq!(Err(&mut 1).cloned(), Err(1));
1111+
/// assert_eq!(Ok(&mut 42).cloned(), Ok(42));
1112+
/// ```
1113+
#[unstable(feature = "result_cloned", reason = "newly added", issue = "63168")]
1114+
pub fn cloned(self) -> Result<T, E> {
1115+
self.cloned_ok().cloned_err()
1116+
}
1117+
}
1118+
9831119
impl<T, E: fmt::Debug> Result<T, E> {
9841120
/// Unwraps a result, yielding the content of an [`Ok`].
9851121
///

0 commit comments

Comments
 (0)