diff options
| author | Shanavas M <shanavas.m2@gmail.com> | 2017-11-11 17:01:55 +0300 |
|---|---|---|
| committer | Shanavas M <shanavas.m2@gmail.com> | 2017-11-11 17:32:29 +0300 |
| commit | abff092f907bff0bdf3f640692494f0b7430efa0 (patch) | |
| tree | 62c5a7904e151a1156ca44ee3e8ea19fdf19948d /src/libcore | |
| parent | 69ee5a8a9787336f8635ec12ed0c6199a70505e0 (diff) | |
| download | rust-abff092f907bff0bdf3f640692494f0b7430efa0.tar.gz rust-abff092f907bff0bdf3f640692494f0b7430efa0.zip | |
Refactor Option::filter method
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/option.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 63c846b25ec..12e6e843056 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -634,16 +634,12 @@ impl<T> Option<T> { #[inline] #[unstable(feature = "option_filter", issue = "45860")] pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self { - match self { - Some(x) => { - if predicate(&x) { - Some(x) - } else { - None - } + if let Some(x) = self { + if predicate(&x) { + return Some(x) } - None => None, } + None } /// Returns the option if it contains a value, otherwise returns `optb`. |
