Skip to content

Commit

Permalink
Rollup merge of rust-lang#63000 - max-sixty:chars-display, r=alexcric…
Browse files Browse the repository at this point in the history
…hton

Impl Debug for Chars

Closes rust-lang#62947, making `Debug` more consistent with the struct's output and purpose

Let me know any feedback!
  • Loading branch information
Centril authored Jul 30, 2019
2 parents 3602987 + 3325ff6 commit 51e50ed
Show file tree
Hide file tree
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
Expand Up @@ -1108,6 +1108,16 @@ fn test_iterator_last() {
assert_eq!(it.last(), Some('m'));
}

#[test]
fn test_chars_debug() {
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";
Expand Down
12 changes: 11 additions & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -600,6 +600,16 @@ impl<'a> Iterator for Chars<'a> {
}
}

#[stable(feature = "chars_debug_impl", since = "1.38.0")]
impl fmt::Debug for Chars<'_> {
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]
Expand Down

0 comments on commit 51e50ed

Please sign in to comment.