Skip to content

Commit

Permalink
impl Debug for Chars
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Jul 29, 2019
1 parent 04b88a9 commit 624c5da
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/liballoc/tests/str.rs
Original file line number Diff line number Diff line change
@@ -1108,6 +1108,16 @@ fn test_iterator_last() {
assert_eq!(it.last(), Some('m'));
}

#[test]
fn test_chars_display() {
let s = "ศไทย中华Việt Nam";
let c = s.chars();
assert_eq!(
format!("{:?}", c),
r#"Chars(['ศ', 'ไ', 'ท', 'ย', '中', '华', 'V', 'i', 'ệ', 't', ' ', 'N', 'a', 'm'])"#
);
}

#[test]
fn test_bytesator() {
let s = "ศไทย中华Việt Nam";
12 changes: 11 additions & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
@@ -464,7 +464,7 @@ Section: Iterators
///
/// [`chars`]: ../../std/primitive.str.html#method.chars
/// [`str`]: ../../std/primitive.str.html
#[derive(Clone, Debug)]
#[derive(Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Chars<'a> {
iter: slice::Iter<'a, u8>
@@ -600,6 +600,16 @@ impl<'a> Iterator for Chars<'a> {
}
}

#[stable(feature = "chars_debug_impl", since = "1.38.0")]
impl<'a> fmt::Debug for Chars<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Chars(")?;
f.debug_list().entries(self.clone()).finish()?;
write!(f, ")")?;
Ok(())
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for Chars<'a> {
#[inline]

0 comments on commit 624c5da

Please sign in to comment.