Implement count for EscapeDefault and EscapeUnicode

Trivial implementation, as both are `ExactSizeIterator`s.

Part of #24214.
This commit is contained in:
Andrea Canciani 2015-12-30 16:42:52 +01:00
parent c30fa92a0a
commit baa9680a34

View File

@ -470,6 +470,11 @@ impl Iterator for EscapeUnicode {
(n, Some(n))
}
#[inline]
fn count(self) -> usize {
self.len()
}
fn last(self) -> Option<char> {
match self.state {
EscapeUnicodeState::Done => None,
@ -535,13 +540,9 @@ impl Iterator for EscapeDefault {
}
}
#[inline]
fn count(self) -> usize {
match self.state {
EscapeDefaultState::Char(_) => 1,
EscapeDefaultState::Unicode(iter) => iter.count(),
EscapeDefaultState::Done => 0,
EscapeDefaultState::Backslash(_) => 2,
}
self.len()
}
fn nth(&mut self, n: usize) -> Option<char> {