Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/libcollectionstest/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,37 @@ fn test_bytes_revator() {
}
}

#[test]
fn test_bytesator_nth() {
let s = "ศไทย中华Việt Nam";
let v = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need the whole bytes vector here?

224, 184, 168, 224, 185, 132, 224, 184, 151, 224, 184, 162, 228,
184, 173, 229, 141, 142, 86, 105, 225, 187, 135, 116, 32, 78, 97,
109
];

let mut b = s.bytes();
assert_eq!(b.nth(2).unwrap(), v[2]);
assert_eq!(b.nth(10).unwrap(), v[10]);
assert_eq!(b.nth(200), None);
}

#[test]
fn test_bytesator_count() {
let s = "ศไทย中华Việt Nam";

let b = s.bytes();
assert_eq!(b.count(), 28)
}

#[test]
fn test_bytesator_last() {
let s = "ศไทย中华Việt Nam";

let b = s.bytes();
assert_eq!(b.last().unwrap(), 109)
}

#[test]
fn test_char_indicesator() {
let s = "ศไทย中华Việt Nam";
Expand Down
15 changes: 15 additions & 0 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,21 @@ impl<'a> Iterator for Bytes<'a> {
fn size_hint(&self) -> (usize, Option<usize>) {
self.0.size_hint()
}

#[inline]
fn count(self) -> usize {
self.0.count()
}

#[inline]
fn last(self) -> Option<Self::Item> {
self.0.last()
}

#[inline]
fn nth(&mut self, n: usize) -> Option<Self::Item> {
self.0.nth(n)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down