@@ -448,6 +448,20 @@ impl Into<Vec<u8>> for AsciiString {
448
448
}
449
449
}
450
450
451
+ impl < ' a > From < & ' a AsciiStr > for AsciiString {
452
+ #[ inline]
453
+ fn from ( s : & ' a AsciiStr ) -> Self {
454
+ s. to_ascii_string ( )
455
+ }
456
+ }
457
+
458
+ impl < ' a > From < & ' a [ AsciiChar ] > for AsciiString {
459
+ #[ inline]
460
+ fn from ( s : & ' a [ AsciiChar ] ) -> AsciiString {
461
+ s. into_iter ( ) . map ( |c| * c) . collect ( )
462
+ }
463
+ }
464
+
451
465
impl Into < String > for AsciiString {
452
466
#[ inline]
453
467
fn into ( self ) -> String {
@@ -719,18 +733,29 @@ pub trait IntoAsciiString: Sized {
719
733
fn into_ascii_string ( self ) -> Result < AsciiString , FromAsciiError < Self > > ;
720
734
}
721
735
722
- impl IntoAsciiString for AsciiString {
736
+ impl IntoAsciiString for Vec < AsciiChar > {
723
737
#[ inline]
724
738
unsafe fn into_ascii_string_unchecked ( self ) -> AsciiString {
725
- self
739
+ AsciiString :: from ( self )
740
+ }
741
+ #[ inline]
742
+ fn into_ascii_string ( self ) -> Result < AsciiString , FromAsciiError < Self > > {
743
+ Ok ( AsciiString :: from ( self ) )
744
+ }
745
+ }
746
+
747
+ impl < ' a > IntoAsciiString for & ' a [ AsciiChar ] {
748
+ #[ inline]
749
+ unsafe fn into_ascii_string_unchecked ( self ) -> AsciiString {
750
+ AsciiString :: from ( self )
726
751
}
727
752
#[ inline]
728
- fn into_ascii_string ( self ) -> Result < Self , FromAsciiError < Self > > {
729
- Ok ( self )
753
+ fn into_ascii_string ( self ) -> Result < AsciiString , FromAsciiError < Self > > {
754
+ Ok ( AsciiString :: from ( self ) )
730
755
}
731
756
}
732
757
733
- impl IntoAsciiString for Vec < AsciiChar > {
758
+ impl < ' a > IntoAsciiString for & ' a AsciiStr {
734
759
#[ inline]
735
760
unsafe fn into_ascii_string_unchecked ( self ) -> AsciiString {
736
761
AsciiString :: from ( self )
@@ -771,6 +796,7 @@ macro_rules! impl_into_ascii_string {
771
796
} ;
772
797
}
773
798
799
+ impl_into_ascii_string ! { AsciiString }
774
800
impl_into_ascii_string ! { Vec <u8 >}
775
801
impl_into_ascii_string ! { ' a, & ' a [ u8 ] }
776
802
impl_into_ascii_string ! { String }
0 commit comments