Skip to content

Commit 3604737

Browse files
authored
Rollup merge of #45933 - shanavas786:refactor-filter, r=alexcrichton
Refactor Option::filter method
2 parents 574dff9 + abff092 commit 3604737

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/libcore/option.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -634,16 +634,12 @@ impl<T> Option<T> {
634634
#[inline]
635635
#[unstable(feature = "option_filter", issue = "45860")]
636636
pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
637-
match self {
638-
Some(x) => {
639-
if predicate(&x) {
640-
Some(x)
641-
} else {
642-
None
643-
}
637+
if let Some(x) = self {
638+
if predicate(&x) {
639+
return Some(x)
644640
}
645-
None => None,
646641
}
642+
None
647643
}
648644

649645
/// Returns the option if it contains a value, otherwise returns `optb`.

0 commit comments

Comments
 (0)