We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5bd1e7f commit de2f617Copy full SHA for de2f617
src/libcollectionstest/str.rs
@@ -814,6 +814,14 @@ fn test_iterator_clone() {
814
assert!(it.clone().zip(it).all(|(x,y)| x == y));
815
}
816
817
+#[test]
818
+fn test_iterator_last() {
819
+ let s = "ศไทย中华Việt Nam";
820
+ let mut it = s.chars();
821
+ it.next();
822
+ assert_eq!(it.last(), Some('m'));
823
+}
824
+
825
#[test]
826
fn test_bytesator() {
827
let s = "ศไทย中华Việt Nam";
src/libcore/str/mod.rs
@@ -432,6 +432,12 @@ impl<'a> Iterator for Chars<'a> {
432
// `isize::MAX` (that's well below `usize::MAX`).
433
((len + 3) / 4, Some(len))
434
435
436
+ #[inline]
437
+ fn last(mut self) -> Option<char> {
438
+ // No need to go through the entire string.
439
+ self.next_back()
440
+ }
441
442
443
#[stable(feature = "rust1", since = "1.0.0")]
0 commit comments