@@ -124,12 +124,12 @@ where
124
124
impl < T , const N : usize , Idx > Index < Idx > for CharWindow < T , N >
125
125
where
126
126
T : Iterator < Item = char > ,
127
- Idx : SliceIndex < [ Option < char > ] , Output = Option < char > > ,
127
+ Idx : SliceIndex < [ Option < char > ] > ,
128
128
{
129
- type Output = Option < char > ;
129
+ type Output = Idx :: Output ;
130
130
131
131
fn index ( & self , index : Idx ) -> & Self :: Output {
132
- self . window . index ( index )
132
+ & self . window [ index]
133
133
}
134
134
}
135
135
@@ -199,12 +199,12 @@ where
199
199
fn next ( & mut self ) -> Option < Self :: Item > {
200
200
// Collapse \r\n into \n
201
201
loop {
202
- match ( self . window [ 0 ] , self . window [ 1 ] ) {
203
- ( Some ( '\r' ) , Some ( '\n' ) ) => {
202
+ match self . window [ .. 2 ] {
203
+ [ Some ( '\r' ) , Some ( '\n' ) ] => {
204
204
// Windows EOL into \n
205
205
self . shift ( ) ;
206
206
}
207
- ( Some ( '\r' ) , _) => {
207
+ [ Some ( '\r' ) , _] => {
208
208
// MAC EOL into \n
209
209
self . window . change_first ( '\n' ) ;
210
210
}
@@ -309,20 +309,20 @@ where
309
309
/// Numeric lexing. The feast can start!
310
310
fn lex_number ( & mut self ) -> LexResult {
311
311
let start_pos = self . get_pos ( ) ;
312
- match ( self . window [ 0 ] , self . window [ 1 ] ) {
313
- ( Some ( '0' ) , Some ( 'x' | 'X' ) ) => {
312
+ match self . window [ .. 2 ] {
313
+ [ Some ( '0' ) , Some ( 'x' | 'X' ) ] => {
314
314
// Hex! (0xdeadbeef)
315
315
self . next_char ( ) ;
316
316
self . next_char ( ) ;
317
317
self . lex_number_radix ( start_pos, 16 )
318
318
}
319
- ( Some ( '0' ) , Some ( 'o' | 'O' ) ) => {
319
+ [ Some ( '0' ) , Some ( 'o' | 'O' ) ] => {
320
320
// Octal style! (0o377)
321
321
self . next_char ( ) ;
322
322
self . next_char ( ) ;
323
323
self . lex_number_radix ( start_pos, 8 )
324
324
}
325
- ( Some ( '0' ) , Some ( 'b' | 'B' ) ) => {
325
+ [ Some ( '0' ) , Some ( 'b' | 'B' ) ] => {
326
326
// Binary! (0b_1110_0101)
327
327
self . next_char ( ) ;
328
328
self . next_char ( ) ;
@@ -470,9 +470,9 @@ where
470
470
471
471
/// Test if we face '[eE][-+]?[0-9]+'
472
472
fn at_exponent ( & self ) -> bool {
473
- match ( self . window [ 0 ] , self . window [ 1 ] ) {
474
- ( Some ( 'e' | 'E' ) , Some ( '+' | '-' ) ) => matches ! ( self . window[ 2 ] , Some ( '0' ..='9' ) ) ,
475
- ( Some ( 'e' | 'E' ) , Some ( '0' ..='9' ) ) => true ,
473
+ match self . window [ .. 2 ] {
474
+ [ Some ( 'e' | 'E' ) , Some ( '+' | '-' ) ] => matches ! ( self . window[ 2 ] , Some ( '0' ..='9' ) ) ,
475
+ [ Some ( 'e' | 'E' ) , Some ( '0' ..='9' ) ] => true ,
476
476
_ => false ,
477
477
}
478
478
}
@@ -500,14 +500,13 @@ where
500
500
501
501
// If the next two characters are also the quote character, then we have a triple-quoted
502
502
// string; consume those two characters and ensure that we require a triple-quote to close
503
- let triple_quoted =
504
- if self . window [ 0 ] == Some ( quote_char) && self . window [ 1 ] == Some ( quote_char) {
505
- self . next_char ( ) ;
506
- self . next_char ( ) ;
507
- true
508
- } else {
509
- false
510
- } ;
503
+ let triple_quoted = if self . window [ ..2 ] == [ Some ( quote_char) ; 2 ] {
504
+ self . next_char ( ) ;
505
+ self . next_char ( ) ;
506
+ true
507
+ } else {
508
+ false
509
+ } ;
511
510
512
511
loop {
513
512
match self . next_char ( ) {
@@ -534,9 +533,7 @@ where
534
533
// Look ahead at the next two characters; if we have two more
535
534
// quote_chars, it's the end of the string; consume the remaining
536
535
// closing quotes and break the loop
537
- if self . window [ 0 ] == Some ( quote_char)
538
- && self . window [ 1 ] == Some ( quote_char)
539
- {
536
+ if self . window [ ..2 ] == [ Some ( quote_char) ; 2 ] {
540
537
self . next_char ( ) ;
541
538
self . next_char ( ) ;
542
539
break ;
@@ -1094,7 +1091,7 @@ where
1094
1091
} else {
1095
1092
let tok_start = self . get_pos ( ) ;
1096
1093
self . next_char ( ) ;
1097
- if let ( Some ( '.' ) , Some ( '.' ) ) = ( & self . window [ 0 ] , & self . window [ 1 ] ) {
1094
+ if self . window [ .. 2 ] == [ Some ( '.' ) ; 2 ] {
1098
1095
self . next_char ( ) ;
1099
1096
self . next_char ( ) ;
1100
1097
let tok_end = self . get_pos ( ) ;
0 commit comments