22
22
use std:: default:: Default ;
23
23
use std:: { char, mem, str} ;
24
24
25
- use futf:: { self , Codepoint , Meaning } ;
25
+ use crate :: futf:: { self , Codepoint , Meaning } ;
26
26
27
27
/// Implementation details.
28
28
///
29
29
/// You don't need these unless you are implementing
30
30
/// a new format.
31
31
pub mod imp {
32
32
use std:: default:: Default ;
33
- use std:: { iter, mem , slice} ;
33
+ use std:: { iter, slice} ;
34
34
35
35
/// Describes how to fix up encodings when concatenating.
36
36
///
@@ -55,11 +55,6 @@ pub mod imp {
55
55
}
56
56
}
57
57
58
- #[ inline( always) ]
59
- unsafe fn from_u32_unchecked ( n : u32 ) -> char {
60
- mem:: transmute ( n)
61
- }
62
-
63
58
pub struct SingleByteCharIndices < ' a > {
64
59
inner : iter:: Enumerate < slice:: Iter < ' a , u8 > > ,
65
60
}
@@ -71,7 +66,7 @@ pub mod imp {
71
66
fn next ( & mut self ) -> Option < ( usize , char ) > {
72
67
self . inner
73
68
. next ( )
74
- . map ( |( i, & b) | unsafe { ( i, from_u32_unchecked ( b as u32 ) ) } )
69
+ . map ( |( i, & b) | unsafe { ( i, char :: from_u32_unchecked ( b as u32 ) ) } )
75
70
}
76
71
}
77
72
@@ -293,30 +288,30 @@ unsafe impl Format for UTF8 {
293
288
294
289
#[ inline]
295
290
fn validate_prefix ( buf : & [ u8 ] ) -> bool {
296
- if buf. len ( ) == 0 {
291
+ if buf. is_empty ( ) {
297
292
return true ;
298
293
}
299
- match futf:: classify ( buf, buf. len ( ) - 1 ) {
294
+ matches ! (
295
+ futf:: classify( buf, buf. len( ) - 1 ) ,
300
296
Some ( Codepoint {
301
297
meaning: Meaning :: Whole ( _) ,
302
298
..
303
- } ) => true ,
304
- _ => false ,
305
- }
299
+ } )
300
+ )
306
301
}
307
302
308
303
#[ inline]
309
304
fn validate_suffix ( buf : & [ u8 ] ) -> bool {
310
- if buf. len ( ) == 0 {
305
+ if buf. is_empty ( ) {
311
306
return true ;
312
307
}
313
- match futf:: classify ( buf, 0 ) {
308
+ matches ! (
309
+ futf:: classify( buf, 0 ) ,
314
310
Some ( Codepoint {
315
311
meaning: Meaning :: Whole ( _) ,
316
312
..
317
- } ) => true ,
318
- _ => false ,
319
- }
313
+ } )
314
+ )
320
315
}
321
316
322
317
#[ inline]
@@ -374,10 +369,10 @@ pub struct WTF8;
374
369
375
370
#[ inline]
376
371
fn wtf8_meaningful ( m : Meaning ) -> bool {
377
- match m {
378
- Meaning :: Whole ( _ ) | Meaning :: LeadSurrogate ( _ ) | Meaning :: TrailSurrogate ( _ ) => true ,
379
- _ => false ,
380
- }
372
+ matches ! (
373
+ m ,
374
+ Meaning :: Whole ( _ ) | Meaning :: LeadSurrogate ( _ ) | Meaning :: TrailSurrogate ( _ )
375
+ )
381
376
}
382
377
383
378
unsafe impl Format for WTF8 {
@@ -405,7 +400,7 @@ unsafe impl Format for WTF8 {
405
400
406
401
#[ inline]
407
402
fn validate_prefix ( buf : & [ u8 ] ) -> bool {
408
- if buf. len ( ) == 0 {
403
+ if buf. is_empty ( ) {
409
404
return true ;
410
405
}
411
406
match futf:: classify ( buf, buf. len ( ) - 1 ) {
@@ -416,7 +411,7 @@ unsafe impl Format for WTF8 {
416
411
417
412
#[ inline]
418
413
fn validate_suffix ( buf : & [ u8 ] ) -> bool {
419
- if buf. len ( ) == 0 {
414
+ if buf. is_empty ( ) {
420
415
return true ;
421
416
}
422
417
match futf:: classify ( buf, 0 ) {
@@ -432,7 +427,7 @@ unsafe impl Format for WTF8 {
432
427
433
428
#[ inline]
434
429
unsafe fn fixup ( lhs : & [ u8 ] , rhs : & [ u8 ] ) -> imp:: Fixup {
435
- const ERR : & ' static str = "WTF8: internal error" ;
430
+ const ERR : & str = "WTF8: internal error" ;
436
431
437
432
if lhs. len ( ) >= 3 && rhs. len ( ) >= 3 {
438
433
if let (
0 commit comments