@@ -299,6 +299,7 @@ impl AsciiChar {
299
299
}
300
300
301
301
/// Constructs an ASCII character from a `char` or `u8` without any checks.
302
+ #[ inline]
302
303
pub unsafe fn from_unchecked < C : ToAsciiChar > ( ch : C ) -> Self {
303
304
ch. to_ascii_char_unchecked ( )
304
305
}
@@ -477,6 +478,7 @@ impl AsciiChar {
477
478
/// Maps letters `a`...`z` to `A`...`Z` and returns everything else unchanged.
478
479
///
479
480
/// A replacement for `AsciiExt::to_ascii_uppercase()`.
481
+ #[ inline]
480
482
pub fn to_ascii_uppercase ( & self ) -> Self {
481
483
unsafe { match * self as u8 {
482
484
b'a' ...b'z' => AsciiChar :: from_unchecked ( self . as_byte ( ) - ( b'a' - b'A' ) ) ,
@@ -488,6 +490,7 @@ impl AsciiChar {
488
490
/// Maps letters `A`...`Z` to `a`...`z` and returns everything else unchanged.
489
491
///
490
492
/// A replacement for `AsciiExt::to_ascii_lowercase()`.
493
+ #[ inline]
491
494
pub fn to_ascii_lowercase ( & self ) -> Self {
492
495
unsafe { match * self as u8 {
493
496
b'A' ...b'Z' => AsciiChar :: from_unchecked ( self . as_byte ( ) + ( b'a' - b'A' ) ) ,
@@ -505,12 +508,14 @@ impl AsciiChar {
505
508
}
506
509
507
510
impl fmt:: Display for AsciiChar {
511
+ #[ inline]
508
512
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
509
513
self . as_char ( ) . fmt ( f)
510
514
}
511
515
}
512
516
513
517
impl fmt:: Debug for AsciiChar {
518
+ #[ inline]
514
519
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
515
520
self . as_char ( ) . fmt ( f)
516
521
}
@@ -525,10 +530,12 @@ impl AsciiExt for AsciiChar {
525
530
true
526
531
}
527
532
533
+ #[ inline]
528
534
fn to_ascii_uppercase ( & self ) -> AsciiChar {
529
535
unsafe { self . as_byte ( ) . to_ascii_uppercase ( ) . to_ascii_char_unchecked ( ) }
530
536
}
531
537
538
+ #[ inline]
532
539
fn to_ascii_lowercase ( & self ) -> AsciiChar {
533
540
unsafe { self . as_byte ( ) . to_ascii_lowercase ( ) . to_ascii_char_unchecked ( ) }
534
541
}
@@ -550,26 +557,31 @@ impl AsciiExt for AsciiChar {
550
557
551
558
macro_rules! impl_into_partial_eq_ord { ( $wider: ty, $to_wider: expr) => {
552
559
impl From <AsciiChar > for $wider {
560
+ #[ inline]
553
561
fn from( a: AsciiChar ) -> $wider {
554
562
$to_wider( a)
555
563
}
556
564
}
557
565
impl PartialEq <$wider> for AsciiChar {
566
+ #[ inline]
558
567
fn eq( & self , rhs: & $wider) -> bool {
559
568
$to_wider( * self ) == * rhs
560
569
}
561
570
}
562
571
impl PartialEq <AsciiChar > for $wider {
572
+ #[ inline]
563
573
fn eq( & self , rhs: & AsciiChar ) -> bool {
564
574
* self == $to_wider( * rhs)
565
575
}
566
576
}
567
577
impl PartialOrd <$wider> for AsciiChar {
578
+ #[ inline]
568
579
fn partial_cmp( & self , rhs: & $wider) -> Option <Ordering > {
569
580
$to_wider( * self ) . partial_cmp( rhs)
570
581
}
571
582
}
572
583
impl PartialOrd <AsciiChar > for $wider {
584
+ #[ inline]
573
585
fn partial_cmp( & self , rhs: & AsciiChar ) -> Option <Ordering > {
574
586
self . partial_cmp( & $to_wider( * rhs) )
575
587
}
@@ -588,6 +600,7 @@ const ERRORMSG_CHAR: &'static str = "not an ASCII character";
588
600
#[ cfg( feature = "no_std" ) ]
589
601
impl ToAsciiCharError {
590
602
/// Returns a description for this error, like `std::error::Error::description`.
603
+ #[ inline]
591
604
pub fn description ( & self ) -> & ' static str {
592
605
ERRORMSG_CHAR
593
606
}
@@ -607,6 +620,7 @@ impl fmt::Display for ToAsciiCharError {
607
620
608
621
#[ cfg( not( feature = "no_std" ) ) ]
609
622
impl Error for ToAsciiCharError {
623
+ #[ inline]
610
624
fn description ( & self ) -> & ' static str {
611
625
ERRORMSG_CHAR
612
626
}
@@ -621,33 +635,39 @@ pub trait ToAsciiChar {
621
635
}
622
636
623
637
impl ToAsciiChar for AsciiChar {
638
+ #[ inline]
624
639
fn to_ascii_char ( self ) -> Result < AsciiChar , ToAsciiCharError > {
625
640
Ok ( self )
626
641
}
642
+ #[ inline]
627
643
unsafe fn to_ascii_char_unchecked ( self ) -> AsciiChar {
628
644
self
629
645
}
630
646
}
631
647
632
648
impl ToAsciiChar for u8 {
649
+ #[ inline]
633
650
fn to_ascii_char ( self ) -> Result < AsciiChar , ToAsciiCharError > {
634
651
unsafe { if self <= 0x7F {
635
652
return Ok ( self . to_ascii_char_unchecked ( ) ) ;
636
653
} }
637
654
Err ( ToAsciiCharError ( ( ) ) )
638
655
}
656
+ #[ inline]
639
657
unsafe fn to_ascii_char_unchecked ( self ) -> AsciiChar {
640
658
transmute ( self )
641
659
}
642
660
}
643
661
644
662
impl ToAsciiChar for char {
663
+ #[ inline]
645
664
fn to_ascii_char ( self ) -> Result < AsciiChar , ToAsciiCharError > {
646
665
unsafe { if self as u32 <= 0x7F {
647
666
return Ok ( self . to_ascii_char_unchecked ( ) ) ;
648
667
} }
649
668
Err ( ToAsciiCharError ( ( ) ) )
650
669
}
670
+ #[ inline]
651
671
unsafe fn to_ascii_char_unchecked ( self ) -> AsciiChar {
652
672
( self as u8 ) . to_ascii_char_unchecked ( )
653
673
}
0 commit comments