diff options
| author | Clar Fon <them@lightdark.xyz> | 2019-08-09 14:58:09 -0400 |
|---|---|---|
| committer | Clar Fon <them@lightdark.xyz> | 2019-08-09 22:45:06 -0400 |
| commit | 51ce121592f85a22b8f8f1905525efaa89d07d20 (patch) | |
| tree | 193cb3045d092188f0d5b85d5161c9c83afa8c17 | |
| parent | 534b42394d743511db1335d5ed08d507ab7c6e73 (diff) | |
| download | rust-51ce121592f85a22b8f8f1905525efaa89d07d20.tar.gz rust-51ce121592f85a22b8f8f1905525efaa89d07d20.zip | |
Implement Clone, Display for ascii::EscapeDefault
| -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 { |
