diff options
| author | Kyle Huey <khuey@kylehuey.com> | 2019-04-19 21:13:37 -0700 |
|---|---|---|
| committer | Kyle Huey <khuey@kylehuey.com> | 2019-04-19 21:52:43 -0700 |
| commit | 3e86cf36b5114f201868bf459934fe346a76a2d4 (patch) | |
| tree | 60a7de7db6b5733586c144a3dfe113c1fc70dfcd /src/libcore | |
| parent | 8aaae4294b16b8070a52b858364f440873bfc95c (diff) | |
| download | rust-3e86cf36b5114f201868bf459934fe346a76a2d4.tar.gz rust-3e86cf36b5114f201868bf459934fe346a76a2d4.zip | |
Add implementations of last in terms of next_back on a bunch of DoubleEndedIterators.
r?Manishearth
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ascii.rs | 2 | ||||
| -rw-r--r-- | src/libcore/iter/adapters/mod.rs | 5 | ||||
| -rw-r--r-- | src/libcore/slice/mod.rs | 20 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 20 |
4 files changed, 47 insertions, 0 deletions
diff --git a/src/libcore/ascii.rs b/src/libcore/ascii.rs index c0ab364380f..ddee02ea232 100644 --- a/src/libcore/ascii.rs +++ b/src/libcore/ascii.rs @@ -117,6 +117,8 @@ impl Iterator for EscapeDefault { type Item = u8; fn next(&mut self) -> Option<u8> { self.range.next().map(|i| self.data[i]) } fn size_hint(&self) -> (usize, Option<usize>) { self.range.size_hint() } + #[inline] + fn last(mut self) -> Option<u8> { self.next_back() } } #[stable(feature = "rust1", since = "1.0.0")] impl DoubleEndedIterator for EscapeDefault { diff --git a/src/libcore/iter/adapters/mod.rs b/src/libcore/iter/adapters/mod.rs index 3ab404a48d3..d814e8a5958 100644 --- a/src/libcore/iter/adapters/mod.rs +++ b/src/libcore/iter/adapters/mod.rs @@ -73,6 +73,11 @@ impl<I> Iterator for Rev<I> where I: DoubleEndedIterator { { self.iter.position(predicate) } + + #[inline] + fn last(mut self) -> Option<Self::Item> { + self.next_back() + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index bf3dda48dc7..cda4268607f 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -3539,6 +3539,11 @@ impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool { (1, Some(self.v.len() + 1)) } } + + #[inline] + fn last(mut self) -> Option<Self::Item> { + self.next_back() + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -3637,6 +3642,11 @@ impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool { (1, Some(self.v.len() + 1)) } } + + #[inline] + fn last(mut self) -> Option<Self::Item> { + self.next_back() + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -3702,6 +3712,11 @@ impl<'a, T, P> Iterator for RSplit<'a, T, P> where P: FnMut(&T) -> bool { fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() } + + #[inline] + fn last(mut self) -> Option<Self::Item> { + self.next_back() + } } #[stable(feature = "slice_rsplit", since = "1.27.0")] @@ -3766,6 +3781,11 @@ impl<'a, T, P> Iterator for RSplitMut<'a, T, P> where P: FnMut(&T) -> bool { fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() } + + #[inline] + fn last(mut self) -> Option<Self::Item> { + self.next_back() + } } #[stable(feature = "slice_rsplit", since = "1.27.0")] diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 379c263c04c..41399d21942 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1331,6 +1331,11 @@ impl<'a> Iterator for Lines<'a> { fn size_hint(&self) -> (usize, Option<usize>) { self.0.size_hint() } + + #[inline] + fn last(mut self) -> Option<Self::Item> { + self.next_back() + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -1377,6 +1382,11 @@ impl<'a> Iterator for LinesAny<'a> { fn size_hint(&self) -> (usize, Option<usize>) { self.0.size_hint() } + + #[inline] + fn last(mut self) -> Option<Self::Item> { + self.next_back() + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -4215,6 +4225,11 @@ impl<'a> Iterator for SplitWhitespace<'a> { fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() } + + #[inline] + fn last(mut self) -> Option<Self::Item> { + self.next_back() + } } #[stable(feature = "split_whitespace", since = "1.1.0")] @@ -4241,6 +4256,11 @@ impl<'a> Iterator for SplitAsciiWhitespace<'a> { fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() } + + #[inline] + fn last(mut self) -> Option<Self::Item> { + self.next_back() + } } #[stable(feature = "split_ascii_whitespace", since = "1.34.0")] |
