@@ -309,6 +309,58 @@ impl<T, E> Result<T, E> {
309309 !self . is_ok ( )
310310 }
311311
312+ /// Returns `true` if the result is an [`Ok`] value containing the given value.
313+ ///
314+ /// # Examples
315+ ///
316+ /// ```
317+ /// #![feature(option_result_contains)]
318+ ///
319+ /// let x: Result<u32, &str> = Ok(2);
320+ /// assert_eq!(x.contains(&2), true);
321+ ///
322+ /// let x: Result<u32, &str> = Ok(3);
323+ /// assert_eq!(x.contains(&2), false);
324+ ///
325+ /// let x: Result<u32, &str> = Err("Some error message");
326+ /// assert_eq!(x.contains(&2), false);
327+ /// ```
328+ #[ must_use]
329+ #[ inline]
330+ #[ unstable( feature = "option_result_contains" , issue = "62358" ) ]
331+ pub fn contains < U > ( & self , x : & U ) -> bool where U : PartialEq < T > {
332+ match self {
333+ Ok ( y) => x == y,
334+ Err ( _) => false
335+ }
336+ }
337+
338+ /// Returns `true` if the result is an [`Err`] value containing the given value.
339+ ///
340+ /// # Examples
341+ ///
342+ /// ```
343+ /// #![feature(result_contains_err)]
344+ ///
345+ /// let x: Result<u32, &str> = Ok(2);
346+ /// assert_eq!(x.contains_err(&"Some error message"), false);
347+ ///
348+ /// let x: Result<u32, &str> = Err("Some error message");
349+ /// assert_eq!(x.contains_err(&"Some error message"), true);
350+ ///
351+ /// let x: Result<u32, &str> = Err("Some other error message");
352+ /// assert_eq!(x.contains_err(&"Some error message"), false);
353+ /// ```
354+ #[ must_use]
355+ #[ inline]
356+ #[ unstable( feature = "result_contains_err" , issue = "62358" ) ]
357+ pub fn contains_err < F > ( & self , f : & F ) -> bool where F : PartialEq < E > {
358+ match self {
359+ Ok ( _) => false ,
360+ Err ( e) => f == e
361+ }
362+ }
363+
312364 /////////////////////////////////////////////////////////////////////////
313365 // Adapter for each variant
314366 /////////////////////////////////////////////////////////////////////////
0 commit comments