@@ -563,64 +563,6 @@ impl<T, E> Result<T, E> {
563563 !self . is_ok ( )
564564 }
565565
566- /// Returns `true` if the result is an [`Ok`] value containing the given value.
567- ///
568- /// # Examples
569- ///
570- /// ```
571- /// #![feature(option_result_contains)]
572- ///
573- /// let x: Result<u32, &str> = Ok(2);
574- /// assert_eq!(x.contains(&2), true);
575- ///
576- /// let x: Result<u32, &str> = Ok(3);
577- /// assert_eq!(x.contains(&2), false);
578- ///
579- /// let x: Result<u32, &str> = Err("Some error message");
580- /// assert_eq!(x.contains(&2), false);
581- /// ```
582- #[ must_use]
583- #[ inline]
584- #[ unstable( feature = "option_result_contains" , issue = "62358" ) ]
585- pub fn contains < U > ( & self , x : & U ) -> bool
586- where
587- U : PartialEq < T > ,
588- {
589- match self {
590- Ok ( y) => x == y,
591- Err ( _) => false ,
592- }
593- }
594-
595- /// Returns `true` if the result is an [`Err`] value containing the given value.
596- ///
597- /// # Examples
598- ///
599- /// ```
600- /// #![feature(result_contains_err)]
601- ///
602- /// let x: Result<u32, &str> = Ok(2);
603- /// assert_eq!(x.contains_err(&"Some error message"), false);
604- ///
605- /// let x: Result<u32, &str> = Err("Some error message");
606- /// assert_eq!(x.contains_err(&"Some error message"), true);
607- ///
608- /// let x: Result<u32, &str> = Err("Some other error message");
609- /// assert_eq!(x.contains_err(&"Some error message"), false);
610- /// ```
611- #[ must_use]
612- #[ inline]
613- #[ unstable( feature = "result_contains_err" , issue = "62358" ) ]
614- pub fn contains_err < F > ( & self , f : & F ) -> bool
615- where
616- F : PartialEq < E > ,
617- {
618- match self {
619- Ok ( _) => false ,
620- Err ( e) => f == e,
621- }
622- }
623-
624566 /////////////////////////////////////////////////////////////////////////
625567 // Adapter for each variant
626568 /////////////////////////////////////////////////////////////////////////
@@ -1491,6 +1433,68 @@ impl<T, E> Result<T, E> {
14911433 Err ( e) => e,
14921434 }
14931435 }
1436+
1437+ /////////////////////////////////////////////////////////////////////////
1438+ // Misc or niche
1439+ /////////////////////////////////////////////////////////////////////////
1440+
1441+ /// Returns `true` if the result is an [`Ok`] value containing the given value.
1442+ ///
1443+ /// # Examples
1444+ ///
1445+ /// ```
1446+ /// #![feature(option_result_contains)]
1447+ ///
1448+ /// let x: Result<u32, &str> = Ok(2);
1449+ /// assert_eq!(x.contains(&2), true);
1450+ ///
1451+ /// let x: Result<u32, &str> = Ok(3);
1452+ /// assert_eq!(x.contains(&2), false);
1453+ ///
1454+ /// let x: Result<u32, &str> = Err("Some error message");
1455+ /// assert_eq!(x.contains(&2), false);
1456+ /// ```
1457+ #[ must_use]
1458+ #[ inline]
1459+ #[ unstable( feature = "option_result_contains" , issue = "62358" ) ]
1460+ pub fn contains < U > ( & self , x : & U ) -> bool
1461+ where
1462+ U : PartialEq < T > ,
1463+ {
1464+ match self {
1465+ Ok ( y) => x == y,
1466+ Err ( _) => false ,
1467+ }
1468+ }
1469+
1470+ /// Returns `true` if the result is an [`Err`] value containing the given value.
1471+ ///
1472+ /// # Examples
1473+ ///
1474+ /// ```
1475+ /// #![feature(result_contains_err)]
1476+ ///
1477+ /// let x: Result<u32, &str> = Ok(2);
1478+ /// assert_eq!(x.contains_err(&"Some error message"), false);
1479+ ///
1480+ /// let x: Result<u32, &str> = Err("Some error message");
1481+ /// assert_eq!(x.contains_err(&"Some error message"), true);
1482+ ///
1483+ /// let x: Result<u32, &str> = Err("Some other error message");
1484+ /// assert_eq!(x.contains_err(&"Some error message"), false);
1485+ /// ```
1486+ #[ must_use]
1487+ #[ inline]
1488+ #[ unstable( feature = "result_contains_err" , issue = "62358" ) ]
1489+ pub fn contains_err < F > ( & self , f : & F ) -> bool
1490+ where
1491+ F : PartialEq < E > ,
1492+ {
1493+ match self {
1494+ Ok ( _) => false ,
1495+ Err ( e) => f == e,
1496+ }
1497+ }
14941498}
14951499
14961500impl < T , E > Result < & T , E > {
0 commit comments