diff options
| author | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2017-04-08 03:43:18 +0200 |
|---|---|---|
| committer | Ulrik Sverdrup <bluss@users.noreply.github.com> | 2017-04-08 03:45:48 +0200 |
| commit | 5d2f270395814564f674141a99ace77ea9a03352 (patch) | |
| tree | 77f924c7b1488d285e000c2dafb298216310f4ea /src/libcore/slice | |
| parent | 53f4bc311b5ff11a16185dd40dc116cf6b8cc162 (diff) | |
| download | rust-5d2f270395814564f674141a99ace77ea9a03352.tar.gz rust-5d2f270395814564f674141a99ace77ea9a03352.zip | |
slice: Implement .rfind() for slice iterators Iter and IterMut
Just like the forward case find, implement rfind explicitly
Diffstat (limited to 'src/libcore/slice')
| -rw-r--r-- | src/libcore/slice/mod.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index 6d598677c9b..87dfdfe57b6 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -1190,6 +1190,19 @@ macro_rules! iterator { } } } + + fn rfind<F>(&mut self, mut predicate: F) -> Option<Self::Item> + where F: FnMut(&Self::Item) -> bool, + { + self.rsearch_while(None, move |elt| { + if predicate(&elt) { + SearchWhile::Done(Some(elt)) + } else { + SearchWhile::Continue + } + }) + } + } // search_while is a generalization of the internal iteration methods. |
