1#![stable(feature = "core_ascii", since = "1.26.0")]
11
12use crate::escape::{AlwaysEscaped, EscapeIterInner};
13use crate::fmt;
14use crate::iter::FusedIterator;
15use crate::num::NonZero;
16
17mod ascii_char;
18#[doc(alias("AsciiChar"))]
19#[unstable(feature = "ascii_char", issue = "110998")]
20pub use ascii_char::AsciiChar as Char;
21
22#[must_use = "iterators are lazy and do nothing unless consumed"]
27#[stable(feature = "rust1", since = "1.0.0")]
28#[derive(#[automatically_derived]
#[stable(feature = "rust1", since = "1.0.0")]
impl crate::clone::Clone for EscapeDefault {
#[inline]
fn clone(&self) -> EscapeDefault {
EscapeDefault(crate::clone::Clone::clone(&self.0))
}
}Clone)]
29pub struct EscapeDefault(EscapeIterInner<4, AlwaysEscaped>);
30
31#[stable(feature = "rust1", since = "1.0.0")]
94pub fn escape_default(c: u8) -> EscapeDefault {
95 EscapeDefault::new(c)
96}
97
98impl EscapeDefault {
99 #[inline]
100 pub(crate) const fn new(c: u8) -> Self {
101 Self(EscapeIterInner::ascii(c))
102 }
103
104 #[inline]
105 pub(crate) fn empty() -> Self {
106 Self(EscapeIterInner::empty())
107 }
108}
109
110#[stable(feature = "rust1", since = "1.0.0")]
111impl Iterator for EscapeDefault {
112 type Item = u8;
113
114 #[inline]
115 fn next(&mut self) -> Option<u8> {
116 self.0.next()
117 }
118
119 #[inline]
120 fn size_hint(&self) -> (usize, Option<usize>) {
121 let n = self.0.len();
122 (n, Some(n))
123 }
124
125 #[inline]
126 fn count(self) -> usize {
127 self.0.len()
128 }
129
130 #[inline]
131 fn last(mut self) -> Option<u8> {
132 self.0.next_back()
133 }
134
135 #[inline]
136 fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
137 self.0.advance_by(n)
138 }
139}
140
141#[stable(feature = "rust1", since = "1.0.0")]
142impl DoubleEndedIterator for EscapeDefault {
143 #[inline]
144 fn next_back(&mut self) -> Option<u8> {
145 self.0.next_back()
146 }
147
148 #[inline]
149 fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
150 self.0.advance_back_by(n)
151 }
152}
153
154#[stable(feature = "rust1", since = "1.0.0")]
155impl ExactSizeIterator for EscapeDefault {
156 #[inline]
157 fn len(&self) -> usize {
158 self.0.len()
159 }
160}
161
162#[stable(feature = "fused", since = "1.26.0")]
163impl FusedIterator for EscapeDefault {}
164
165#[stable(feature = "ascii_escape_display", since = "1.39.0")]
166impl fmt::Display for EscapeDefault {
167 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
168 fmt::Display::fmt(&self.0, f)
169 }
170}
171
172#[stable(feature = "std_debug", since = "1.16.0")]
173impl fmt::Debug for EscapeDefault {
174 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
175 f.debug_struct("EscapeDefault").finish_non_exhaustive()
176 }
177}