File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ Unreleased
3
3
* Implement the ` std::ops::AddAssign ` trait for ` AsciiString ` .
4
4
* Implement the ` IntoAsciiString ` trait for ` std::ffi::CStr ` and ` std::ffi::CString ` types,
5
5
and implemented the ` AsAsciiStr ` trait for ` std::ffi::CStr ` type.
6
+ * Implement the ` IntoAsciiString ` for ` std::borrow::Cow ` , where the inner types themselves
7
+ implement ` IntoAsciiString ` .
6
8
7
9
Version 0.9.1 (2018-09-12)
8
10
==========================
Original file line number Diff line number Diff line change @@ -854,6 +854,41 @@ impl<'a> IntoAsciiString for &'a CStr {
854
854
}
855
855
}
856
856
857
+ impl < ' a , B : ?Sized > IntoAsciiString for Cow < ' a , B >
858
+ where
859
+ B : ' a + ToOwned ,
860
+ & ' a B : IntoAsciiString ,
861
+ <B as ToOwned >:: Owned : IntoAsciiString ,
862
+ {
863
+ #[ inline]
864
+ unsafe fn into_ascii_string_unchecked ( self ) -> AsciiString {
865
+ IntoAsciiString :: into_ascii_string_unchecked ( self . into_owned ( ) )
866
+ }
867
+
868
+ fn into_ascii_string ( self ) -> Result < AsciiString , FromAsciiError < Self > > {
869
+ match self {
870
+ Cow :: Owned ( b) => {
871
+ IntoAsciiString :: into_ascii_string ( b)
872
+ . map_err ( |FromAsciiError { error, owner } | {
873
+ FromAsciiError {
874
+ owner : Cow :: Owned ( owner) ,
875
+ error : error,
876
+ }
877
+ } )
878
+ }
879
+ Cow :: Borrowed ( b) => {
880
+ IntoAsciiString :: into_ascii_string ( b)
881
+ . map_err ( |FromAsciiError { error, owner } | {
882
+ FromAsciiError {
883
+ owner : Cow :: Borrowed ( owner) ,
884
+ error : error,
885
+ }
886
+ } )
887
+ }
888
+ }
889
+ }
890
+ }
891
+
857
892
#[ cfg( feature = "quickcheck" ) ]
858
893
impl Arbitrary for AsciiString {
859
894
fn arbitrary < G : Gen > ( g : & mut G ) -> Self {
You can’t perform that action at this time.
0 commit comments