diff options
| author | Maximilian Roos <m@maxroos.com> | 2019-07-26 02:58:37 -0400 |
|---|---|---|
| committer | Maximilian Roos <m@maxroos.com> | 2019-07-29 12:17:59 -0400 |
| commit | 624c5da1aacf44354dead47dce5033f1806e9228 (patch) | |
| tree | a1383f14dc21337219b7d27a10ea4df5855bd7f2 | |
| parent | 04b88a9eba8abbac87eddcb2998beea09589c2c9 (diff) | |
| download | rust-624c5da1aacf44354dead47dce5033f1806e9228.tar.gz rust-624c5da1aacf44354dead47dce5033f1806e9228.zip | |
impl Debug for Chars
| -rw-r--r-- | src/liballoc/tests/str.rs | 10 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 12 |
2 files changed, 21 insertions, 1 deletions
diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index b197516403f..20132fea651 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -1109,6 +1109,16 @@ fn test_iterator_last() { } #[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"; let v = [ diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 4ecaa37460c..ee791748c1d 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -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] |
