mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Rollup merge of #63000 - max-sixty:chars-display, r=alexcrichton
Impl Debug for Chars Closes https://github.com/rust-lang/rust/issues/62947, making `Debug` more consistent with the struct's output and purpose Let me know any feedback!
This commit is contained in:
commit
51e50ed827
@ -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";
|
||||
|
@ -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 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]
|
||||
|
Loading…
Reference in New Issue
Block a user