X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=library%2Fcore%2Fsrc%2Foption.rs;h=1ec119a71e42c84cbc356e1cf4b6f82d24887d1a;hb=1591dcb659917de87254297073b078b9ade56612;hp=0022df4f65ff7cffd1a430d7afbe7b129ba2864d;hpb=2b681ac06b1a6b7ea39525e59363ffee0d1a68e5;p=rust.git diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 0022df4f65f..1ec119a71e4 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -571,36 +571,6 @@ pub const fn is_none(&self) -> bool { !self.is_some() } - /// Returns `true` if the option is a [`Some`] value containing the given value. - /// - /// # Examples - /// - /// ``` - /// #![feature(option_result_contains)] - /// - /// let x: Option = Some(2); - /// assert_eq!(x.contains(&2), true); - /// - /// let x: Option = Some(3); - /// assert_eq!(x.contains(&2), false); - /// - /// let x: Option = None; - /// assert_eq!(x.contains(&2), false); - /// ``` - #[must_use] - #[inline] - #[unstable(feature = "option_result_contains", issue = "62358")] - #[rustc_const_unstable(feature = "const_option_ext", issue = "91930")] - pub const fn contains(&self, x: &U) -> bool - where - U: ~const PartialEq, - { - match self { - Some(y) => x.eq(y), - None => false, - } - } - ///////////////////////////////////////////////////////////////////////// // Adapter for working with references ///////////////////////////////////////////////////////////////////////// @@ -1573,6 +1543,36 @@ pub const fn replace(&mut self, value: T) -> Option { mem::replace(self, Some(value)) } + /// Returns `true` if the option is a [`Some`] value containing the given value. + /// + /// # Examples + /// + /// ``` + /// #![feature(option_result_contains)] + /// + /// let x: Option = Some(2); + /// assert_eq!(x.contains(&2), true); + /// + /// let x: Option = Some(3); + /// assert_eq!(x.contains(&2), false); + /// + /// let x: Option = None; + /// assert_eq!(x.contains(&2), false); + /// ``` + #[must_use] + #[inline] + #[unstable(feature = "option_result_contains", issue = "62358")] + #[rustc_const_unstable(feature = "const_option_ext", issue = "91930")] + pub const fn contains(&self, x: &U) -> bool + where + U: ~const PartialEq, + { + match self { + Some(y) => x.eq(y), + None => false, + } + } + /// Zips `self` with another `Option`. /// /// If `self` is `Some(s)` and `other` is `Some(o)`, this method returns `Some((s, o))`.