Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb482e06

Browse files
committed
add is_none_or
1 parent209f8c8 commitb482e06

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

‎core/src/option.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,32 @@ impl<T> Option<T> {
654654
!self.is_some()
655655
}
656656

657+
/// Returns `true` if the option is a [`None`] or the value inside of it matches a predicate.
658+
///
659+
/// # Examples
660+
///
661+
/// ```
662+
/// #![feature(is_none_or)]
663+
///
664+
/// let x: Option<u32> = Some(2);
665+
/// assert_eq!(x.is_none_or(|x| x > 1), true);
666+
///
667+
/// let x: Option<u32> = Some(0);
668+
/// assert_eq!(x.is_none_or(|x| x > 1), false);
669+
///
670+
/// let x: Option<u32> = None;
671+
/// assert_eq!(x.is_none_or(|x| x > 1), true);
672+
/// ```
673+
#[must_use]
674+
#[inline]
675+
#[unstable(feature ="is_none_or", issue ="none")]
676+
pubfnis_none_or(self,f:implFnOnce(T) ->bool) ->bool{
677+
matchself{
678+
None =>true,
679+
Some(x) =>f(x),
680+
}
681+
}
682+
657683
/////////////////////////////////////////////////////////////////////////
658684
// Adapter for working with references
659685
/////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp