diff options
| author | Mazdak Farrokhzad <twingoow@gmail.com> | 2019-08-14 04:18:39 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-14 04:18:39 +0200 |
| commit | b5df4bb7eb8cd10d31966d86482d6dfb501547fc (patch) | |
| tree | 03e1a75116aa559c869ae0c21d52b5ad5dc19a40 /src/libcore | |
| parent | 3d5387d39b94370a292a2777a549086c16f1e459 (diff) | |
| parent | 51ce121592f85a22b8f8f1905525efaa89d07d20 (diff) | |
| download | rust-b5df4bb7eb8cd10d31966d86482d6dfb501547fc.tar.gz rust-b5df4bb7eb8cd10d31966d86482d6dfb501547fc.zip | |
Rollup merge of #63421 - clarfon:escape_default, r=dtolnay
Implement Clone, Display for ascii::EscapeDefault This will mimic the same behaviour as the `char` version; `Display`ing the iterator will give its string representation without advancing it.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/ascii.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libcore/ascii.rs b/src/libcore/ascii.rs index e6a6fdde540..4087333e2cf 100644 --- a/src/libcore/ascii.rs +++ b/src/libcore/ascii.rs @@ -14,6 +14,7 @@ use crate::fmt; use crate::ops::Range; use crate::iter::FusedIterator; +use crate::str::from_utf8_unchecked; /// An iterator over the escaped version of a byte. /// @@ -22,6 +23,7 @@ use crate::iter::FusedIterator; /// /// [`escape_default`]: fn.escape_default.html #[stable(feature = "rust1", since = "1.0.0")] +#[derive(Clone)] pub struct EscapeDefault { range: Range<usize>, data: [u8; 4], @@ -130,6 +132,13 @@ impl ExactSizeIterator for EscapeDefault {} #[stable(feature = "fused", since = "1.26.0")] impl FusedIterator for EscapeDefault {} +#[stable(feature = "ascii_escape_display", since = "1.39.0")] +impl fmt::Display for EscapeDefault { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str(unsafe { from_utf8_unchecked(&self.data[self.range.clone()]) }) + } +} + #[stable(feature = "std_debug", since = "1.16.0")] impl fmt::Debug for EscapeDefault { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
