@@ -1174,6 +1174,43 @@ impl<T, E> Result<T, E> {
1174
1174
}
1175
1175
}
1176
1176
1177
+ /// Returns the contained [`Ok`] value, but never panics.
1178
+ ///
1179
+ /// Unlike [`unwrap`], this method is known to never panic on the
1180
+ /// result types it is implemented for. Therefore, it can be used
1181
+ /// instead of `unwrap` as a maintainability safeguard that will fail
1182
+ /// to compile if the error type of the `Result` is later changed
1183
+ /// to an error that can actually occur.
1184
+ ///
1185
+ /// [`unwrap`]: Result::unwrap
1186
+ ///
1187
+ /// # Examples
1188
+ ///
1189
+ /// Basic usage:
1190
+ ///
1191
+ /// ```
1192
+ /// # #![feature(never_type)]
1193
+ /// # #![feature(unwrap_infallible)]
1194
+ ///
1195
+ /// fn only_good_news() -> Result<String, !> {
1196
+ /// Ok("this is fine".into())
1197
+ /// }
1198
+ ///
1199
+ /// let s: String = only_good_news().into_ok();
1200
+ /// println!("{}", s);
1201
+ /// ```
1202
+ #[ unstable( feature = "unwrap_infallible" , reason = "newly added" , issue = "61695" ) ]
1203
+ #[ inline]
1204
+ pub fn into_ok ( self ) -> T
1205
+ where
1206
+ E : Into < !> ,
1207
+ {
1208
+ match self {
1209
+ Ok ( x) => x,
1210
+ Err ( e) => e. into ( ) ,
1211
+ }
1212
+ }
1213
+
1177
1214
////////////////////////////////////////////////////////////////////////
1178
1215
// Boolean operations on the values, eager and lazy
1179
1216
/////////////////////////////////////////////////////////////////////////
@@ -1499,42 +1536,6 @@ impl<T: Clone, E> Result<&mut T, E> {
1499
1536
}
1500
1537
}
1501
1538
1502
- #[ unstable( feature = "unwrap_infallible" , reason = "newly added" , issue = "61695" ) ]
1503
- impl < T , E : Into < !> > Result < T , E > {
1504
- /// Returns the contained [`Ok`] value, but never panics.
1505
- ///
1506
- /// Unlike [`unwrap`], this method is known to never panic on the
1507
- /// result types it is implemented for. Therefore, it can be used
1508
- /// instead of `unwrap` as a maintainability safeguard that will fail
1509
- /// to compile if the error type of the `Result` is later changed
1510
- /// to an error that can actually occur.
1511
- ///
1512
- /// [`unwrap`]: Result::unwrap
1513
- ///
1514
- /// # Examples
1515
- ///
1516
- /// Basic usage:
1517
- ///
1518
- /// ```
1519
- /// # #![feature(never_type)]
1520
- /// # #![feature(unwrap_infallible)]
1521
- ///
1522
- /// fn only_good_news() -> Result<String, !> {
1523
- /// Ok("this is fine".into())
1524
- /// }
1525
- ///
1526
- /// let s: String = only_good_news().into_ok();
1527
- /// println!("{}", s);
1528
- /// ```
1529
- #[ inline]
1530
- pub fn into_ok ( self ) -> T {
1531
- match self {
1532
- Ok ( x) => x,
1533
- Err ( e) => e. into ( ) ,
1534
- }
1535
- }
1536
- }
1537
-
1538
1539
#[ unstable( feature = "unwrap_infallible" , reason = "newly added" , issue = "61695" ) ]
1539
1540
impl < T : Into < !> , E > Result < T , E > {
1540
1541
/// Returns the contained [`Err`] value, but never panics.
0 commit comments