#![stable(feature = "rust1", since = "1.0.0")]
use crate::iter::{self, FromIterator, FusedIterator, TrustedLen};
+use crate::marker::Destruct;
use crate::ops::{self, ControlFlow, Deref, DerefMut};
use crate::{convert, fmt, hint};
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
///
/// #![feature(is_some_with)]
///
/// let x: Result<u32, &str> = 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<u32, &str> = 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<u32, &str> = 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))
}
!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
///
/// use std::io::{Error, ErrorKind};
///
/// let x: Result<u32, Error> = 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<u32, Error> = 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<u32, Error> = 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))
}
#[rustc_const_unstable(feature = "const_result_drop", issue = "92384")]
pub const fn ok(self) -> Option<T>
where
- E: ~const Drop,
+ E: ~const Drop + ~const Destruct,
{
match self {
Ok(x) => Some(x),
#[rustc_const_unstable(feature = "const_result_drop", issue = "92384")]
pub const fn err(self) -> Option<E>
where
- T: ~const Drop,
+ T: ~const Drop + ~const Destruct,
{
match self {
// FIXME: ~const Drop doesn't quite work right yet
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn and<U>(self, res: Result<U, E>) -> Result<U, E>
where
- T: ~const Drop,
- U: ~const Drop,
- E: ~const Drop,
+ T: ~const Drop + ~const Destruct,
+ U: ~const Drop + ~const Destruct,
+ E: ~const Drop + ~const Destruct,
{
match self {
// FIXME: ~const Drop doesn't quite work right yet
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn or<F>(self, res: Result<T, F>) -> Result<T, F>
where
- T: ~const Drop,
- E: ~const Drop,
- F: ~const Drop,
+ T: ~const Drop + ~const Destruct,
+ E: ~const Drop + ~const Destruct,
+ F: ~const Drop + ~const Destruct,
{
match self {
Ok(v) => Ok(v),
#[stable(feature = "rust1", since = "1.0.0")]
pub const fn unwrap_or(self, default: T) -> T
where
- T: ~const Drop,
- E: ~const Drop,
+ T: ~const Drop + ~const Destruct,
+ E: ~const Drop + ~const Destruct,
{
match self {
Ok(t) => t,
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_clone", issue = "91805")]
+#[cfg_attr(not(bootstrap), allow(drop_bounds))] // FIXME remove `~const Drop` and this attr when bumping
impl<T, E> const Clone for Result<T, E>
where
- T: ~const Clone + ~const Drop,
- E: ~const Clone + ~const Drop,
+ T: ~const Clone + ~const Drop + ~const Destruct,
+ E: ~const Clone + ~const Drop + ~const Destruct,
{
#[inline]
fn clone(&self) -> Self {