@@ -1211,6 +1211,43 @@ impl<T, E> Result<T, E> {
1211
1211
}
1212
1212
}
1213
1213
1214
+ /// Returns the contained [`Err`] value, but never panics.
1215
+ ///
1216
+ /// Unlike [`unwrap_err`], this method is known to never panic on the
1217
+ /// result types it is implemented for. Therefore, it can be used
1218
+ /// instead of `unwrap_err` as a maintainability safeguard that will fail
1219
+ /// to compile if the ok type of the `Result` is later changed
1220
+ /// to a type that can actually occur.
1221
+ ///
1222
+ /// [`unwrap_err`]: Result::unwrap_err
1223
+ ///
1224
+ /// # Examples
1225
+ ///
1226
+ /// Basic usage:
1227
+ ///
1228
+ /// ```
1229
+ /// # #![feature(never_type)]
1230
+ /// # #![feature(unwrap_infallible)]
1231
+ ///
1232
+ /// fn only_bad_news() -> Result<!, String> {
1233
+ /// Err("Oops, it failed".into())
1234
+ /// }
1235
+ ///
1236
+ /// let error: String = only_bad_news().into_err();
1237
+ /// println!("{}", error);
1238
+ /// ```
1239
+ #[ unstable( feature = "unwrap_infallible" , reason = "newly added" , issue = "61695" ) ]
1240
+ #[ inline]
1241
+ pub fn into_err ( self ) -> E
1242
+ where
1243
+ T : Into < !> ,
1244
+ {
1245
+ match self {
1246
+ Ok ( x) => x. into ( ) ,
1247
+ Err ( e) => e,
1248
+ }
1249
+ }
1250
+
1214
1251
////////////////////////////////////////////////////////////////////////
1215
1252
// Boolean operations on the values, eager and lazy
1216
1253
/////////////////////////////////////////////////////////////////////////
@@ -1536,42 +1573,6 @@ impl<T: Clone, E> Result<&mut T, E> {
1536
1573
}
1537
1574
}
1538
1575
1539
- #[ unstable( feature = "unwrap_infallible" , reason = "newly added" , issue = "61695" ) ]
1540
- impl < T : Into < !> , E > Result < T , E > {
1541
- /// Returns the contained [`Err`] value, but never panics.
1542
- ///
1543
- /// Unlike [`unwrap_err`], this method is known to never panic on the
1544
- /// result types it is implemented for. Therefore, it can be used
1545
- /// instead of `unwrap_err` as a maintainability safeguard that will fail
1546
- /// to compile if the ok type of the `Result` is later changed
1547
- /// to a type that can actually occur.
1548
- ///
1549
- /// [`unwrap_err`]: Result::unwrap_err
1550
- ///
1551
- /// # Examples
1552
- ///
1553
- /// Basic usage:
1554
- ///
1555
- /// ```
1556
- /// # #![feature(never_type)]
1557
- /// # #![feature(unwrap_infallible)]
1558
- ///
1559
- /// fn only_bad_news() -> Result<!, String> {
1560
- /// Err("Oops, it failed".into())
1561
- /// }
1562
- ///
1563
- /// let error: String = only_bad_news().into_err();
1564
- /// println!("{}", error);
1565
- /// ```
1566
- #[ inline]
1567
- pub fn into_err ( self ) -> E {
1568
- match self {
1569
- Ok ( x) => x. into ( ) ,
1570
- Err ( e) => e,
1571
- }
1572
- }
1573
- }
1574
-
1575
1576
impl < T , E > Result < Option < T > , E > {
1576
1577
/// Transposes a `Result` of an `Option` into an `Option` of a `Result`.
1577
1578
///
0 commit comments