@@ -181,23 +181,26 @@ pub(crate) struct MaybeEscaped;
181
181
pub ( crate ) struct EscapeIterInner < const N : usize , ESCAPING > {
182
182
// Invariant:
183
183
//
184
- // If `alive.end <= 128 `, `data.escape_seq` must be valid and
184
+ // If `alive.end <= Self::LITERAL_ESCAPE_START `, `data.escape_seq` must be valid and
185
185
// contain printable ASCII characters in the `alive` range.
186
- // If `alive.end > 128 `, `data.literal` must be valid and
186
+ // If `alive.end > Self::LITERAL_ESCAPE_START `, `data.literal` must be valid and
187
187
// the `alive` range must have a length of at most `1`.
188
188
data : MaybeEscapedCharacter < N > ,
189
189
alive : Range < u8 > ,
190
190
escaping : PhantomData < ESCAPING > ,
191
191
}
192
192
193
193
impl < const N : usize , ESCAPING > EscapeIterInner < N , ESCAPING > {
194
+ const LITERAL_ESCAPE_START : u8 = 128 ;
195
+
194
196
/// # Safety
195
197
///
196
198
/// `data.escape_seq` must contain an escape sequence in the range given by `alive`.
197
199
#[ inline]
198
200
const unsafe fn new ( data : MaybeEscapedCharacter < N > , alive : Range < u8 > ) -> Self {
199
- // Longer escape sequences are not useful given `alive.end` is at most 128.
200
- const { assert ! ( N < 128 ) } ;
201
+ // Longer escape sequences are not useful given `alive.end` is at most
202
+ // `Self::LITERAL_ESCAPE_START`.
203
+ const { assert ! ( N < Self :: LITERAL_ESCAPE_START ) } ;
201
204
Self { data, alive, escaping : PhantomData }
202
205
}
203
206
@@ -263,17 +266,17 @@ impl<const N: usize> EscapeIterInner<N, MaybeEscaped> {
263
266
pub ( crate ) const fn printable ( c : char ) -> Self {
264
267
Self {
265
268
data : MaybeEscapedCharacter { literal : c } ,
266
- // Uphold invariant (`alive.end > 128 `), and ensure `len` behaves
267
- // correctly for iterating through one character literal.
268
- alive : 128 .. 129 ,
269
+ // Uphold invariant (`alive.end > Self::LITERAL_ESCAPE_START `), and ensure `len`
270
+ // behaves correctly for iterating through one character literal.
271
+ alive : Self :: LITERAL_ESCAPE_START .. ( Self :: LITERAL_ESCAPE_START + 1 ) ,
269
272
escaping : PhantomData ,
270
273
}
271
274
}
272
275
273
276
pub ( crate ) fn next ( & mut self ) -> Option < char > {
274
277
let i = self . alive . next ( ) ?;
275
278
276
- if self . alive . end > 128 {
279
+ if self . alive . end > Self :: LITERAL_ESCAPE_START {
277
280
// SAFETY: We just checked that `self.data.literal` is valid.
278
281
return Some ( unsafe { self . data . literal } ) ;
279
282
}
@@ -297,7 +300,7 @@ impl<const N: usize> fmt::Display for EscapeIterInner<N, AlwaysEscaped> {
297
300
298
301
impl < const N : usize > fmt:: Display for EscapeIterInner < N , MaybeEscaped > {
299
302
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
300
- if self . alive . end > 128 {
303
+ if self . alive . end > Self :: LITERAL_ESCAPE_START {
301
304
// SAFETY: We just checked that `self.data.literal` is valid.
302
305
return f. write_char ( unsafe { self . data . literal } ) ;
303
306
}
@@ -323,7 +326,7 @@ impl<const N: usize> fmt::Debug for EscapeIterInner<N, AlwaysEscaped> {
323
326
impl < const N : usize > fmt:: Debug for EscapeIterInner < N , MaybeEscaped > {
324
327
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
325
328
let mut d = f. debug_tuple ( "EscapeIterInner" ) ;
326
- if self . alive . end > 128 {
329
+ if self . alive . end > Self :: LITERAL_ESCAPE_START {
327
330
// SAFETY: We just checked that `self.data.literal` is valid.
328
331
d. field ( unsafe { & self . data . literal } ) ;
329
332
} else {
0 commit comments