From 7c7411fb5d6860d4687acd150e3e606c7f424686 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Wed, 9 Mar 2022 11:20:36 +0100 Subject: [PATCH] Rename is_{some,ok,err}_with to is_{some,ok,err}_and. --- library/core/src/option.rs | 10 +++++----- library/core/src/result.rs | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 508837f63c3be..9df56b3bfd51b 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -551,7 +551,7 @@ impl Option { matches!(*self, Some(_)) } - /// Returns `true` if the option is a [`Some`] wrapping a value matching the predicate. + /// Returns `true` if the option is a [`Some`] and the value inside of it matches a predicate. /// /// # Examples /// @@ -559,18 +559,18 @@ impl Option { /// #![feature(is_some_with)] /// /// let x: Option = Some(2); - /// assert_eq!(x.is_some_with(|&x| x > 1), true); + /// assert_eq!(x.is_some_and(|&x| x > 1), true); /// /// let x: Option = Some(0); - /// assert_eq!(x.is_some_with(|&x| x > 1), false); + /// assert_eq!(x.is_some_and(|&x| x > 1), false); /// /// let x: Option = None; - /// assert_eq!(x.is_some_with(|&x| x > 1), false); + /// assert_eq!(x.is_some_and(|&x| x > 1), false); /// ``` #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_some_with(&self, f: impl FnOnce(&T) -> bool) -> bool { + pub fn is_some_and(&self, f: impl FnOnce(&T) -> bool) -> bool { matches!(self, Some(x) if f(x)) } diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 1827860a39045..e5a4dc06c6421 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -542,7 +542,7 @@ impl Result { matches!(*self, Ok(_)) } - /// Returns `true` if the result is [`Ok`] wrapping a value matching the predicate. + /// Returns `true` if the result is [`Ok`] and the value inside of it matches a predicate. /// /// # Examples /// @@ -550,18 +550,18 @@ impl Result { /// #![feature(is_some_with)] /// /// let x: Result = Ok(2); - /// assert_eq!(x.is_ok_with(|&x| x > 1), true); + /// assert_eq!(x.is_ok_and(|&x| x > 1), true); /// /// let x: Result = Ok(0); - /// assert_eq!(x.is_ok_with(|&x| x > 1), false); + /// assert_eq!(x.is_ok_and(|&x| x > 1), false); /// /// let x: Result = Err("hey"); - /// assert_eq!(x.is_ok_with(|&x| x > 1), false); + /// assert_eq!(x.is_ok_and(|&x| x > 1), false); /// ``` #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_ok_with(&self, f: impl FnOnce(&T) -> bool) -> bool { + pub fn is_ok_and(&self, f: impl FnOnce(&T) -> bool) -> bool { matches!(self, Ok(x) if f(x)) } @@ -586,7 +586,7 @@ impl Result { !self.is_ok() } - /// Returns `true` if the result is [`Err`] wrapping a value matching the predicate. + /// Returns `true` if the result is [`Err`] and the value inside of it matches a predicate. /// /// # Examples /// @@ -595,18 +595,18 @@ impl Result { /// use std::io::{Error, ErrorKind}; /// /// let x: Result = Err(Error::new(ErrorKind::NotFound, "!")); - /// assert_eq!(x.is_err_with(|x| x.kind() == ErrorKind::NotFound), true); + /// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), true); /// /// let x: Result = Err(Error::new(ErrorKind::PermissionDenied, "!")); - /// assert_eq!(x.is_err_with(|x| x.kind() == ErrorKind::NotFound), false); + /// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); /// /// let x: Result = Ok(123); - /// assert_eq!(x.is_err_with(|x| x.kind() == ErrorKind::NotFound), false); + /// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); /// ``` #[must_use] #[inline] #[unstable(feature = "is_some_with", issue = "93050")] - pub fn is_err_with(&self, f: impl FnOnce(&E) -> bool) -> bool { + pub fn is_err_and(&self, f: impl FnOnce(&E) -> bool) -> bool { matches!(self, Err(x) if f(x)) }