The default implementation of last() goes through the entire iterator
but that's not needed here.
assert!(it.clone().zip(it).all(|(x,y)| x == y));
}
+#[test]
+fn test_iterator_last() {
+ let s = "ศไทย中华Việt Nam";
+ let mut it = s.chars();
+ it.next();
+ assert_eq!(it.last(), Some('m'));
+}
+
#[test]
fn test_bytesator() {
let s = "ศไทย中华Việt Nam";
// `isize::MAX` (that's well below `usize::MAX`).
((len + 3) / 4, Some(len))
}
+
+ #[inline]
+ fn last(mut self) -> Option<char> {
+ // No need to go through the entire string.
+ self.next_back()
+ }
}
#[stable(feature = "rust1", since = "1.0.0")]