Skip to content

Commit ff668ec

Browse files
committed
Peek by cloning on Chars
1 parent ec565f6 commit ff668ec

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

library/core/src/str/iter.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,7 @@ impl<'a> DoubleEndedIterator for Chars<'a> {
135135
#[unstable(feature = "peekable_iterator", issue = "132973")]
136136
impl<'a> PeekableIterator for Chars<'a> {
137137
fn peek_with<T>(&mut self, func: impl for<'b> FnOnce(Option<&'b Self::Item>) -> T) -> T {
138-
// SAFETY: `str` invariant says `self.iter` is a valid UTF-8 string and
139-
// the resulting `ch` is a valid Unicode Scalar Value.
140-
let tmp = unsafe {
141-
next_code_point(&mut self.iter.clone()).map(|ch| char::from_u32_unchecked(ch))
142-
};
138+
let tmp = self.clone().next();
143139
func(&tmp)
144140
}
145141
}

0 commit comments

Comments
 (0)