4545#[ cfg( feature = "nightly" ) ]
4646extern crate test;
4747
48+ use std:: borrow:: Cow ;
4849#[ cfg( __unicase__iter_cmp) ]
4950use std:: cmp:: Ordering ;
5051use std:: fmt;
@@ -62,7 +63,7 @@ mod unicode;
6263pub struct UniCase < S > ( Encoding < S > ) ;
6364
6465/// Case Insensitive wrapper of Ascii strings.
65- #[ derive( Clone , Copy , Debug ) ]
66+ #[ derive( Clone , Copy , Debug , Default ) ]
6667pub struct Ascii < S > ( S ) ;
6768
6869/// Compare two string-like types for case-less equality, using unicode folding.
@@ -106,6 +107,12 @@ macro_rules! inner {
106107 } ) ;
107108}
108109
110+ impl < S : AsRef < str > + Default > Default for UniCase < S > {
111+ fn default ( ) -> Self {
112+ Self :: new ( Default :: default ( ) )
113+ }
114+ }
115+
109116impl < S : AsRef < str > > UniCase < S > {
110117 /// Creates a new `UniCase`.
111118 ///
@@ -126,6 +133,17 @@ impl<S: AsRef<str>> UniCase<S> {
126133 }
127134}
128135
136+ impl < S > UniCase < S > {
137+ /// Unwraps the inner value held by this `UniCase`.
138+ #[ inline]
139+ pub fn into_inner ( self ) -> S {
140+ match self . 0 {
141+ Encoding :: Ascii ( s) => s. 0 ,
142+ Encoding :: Unicode ( s) => s. 0 ,
143+ }
144+ }
145+ }
146+
129147impl < S > Deref for UniCase < S > {
130148 type Target = S ;
131149 #[ inline]
@@ -203,22 +221,27 @@ macro_rules! into_impl {
203221 ( $to: ty) => (
204222 impl <' a> Into <$to> for UniCase <$to> {
205223 fn into( self ) -> $to {
206- match self . 0 {
207- Encoding :: Ascii ( Ascii ( s) ) => s,
208- Encoding :: Unicode ( Unicode ( s) ) => s,
209- }
224+ self . into_inner( )
210225 }
211226 }
212227 ) ;
213228}
214229
215- from_impl ! ( & ' a str => & ' a str ) ;
230+ impl < S : AsRef < str > > From < S > for UniCase < S > {
231+ fn from ( s : S ) -> Self {
232+ UniCase :: unicode ( s)
233+ }
234+ }
235+
236+ from_impl ! ( & ' a str => Cow <' a, str >) ;
237+ from_impl ! ( String => Cow <' a, str >) ;
216238from_impl ! ( & ' a str => String ) ;
239+ from_impl ! ( Cow <' a, str > => String ; into_owned) ;
217240from_impl ! ( & ' a String => & ' a str ; as_ref) ;
218- from_impl ! ( String => String ) ;
219241
220242into_impl ! ( & ' a str ) ;
221243into_impl ! ( String ) ;
244+ into_impl ! ( Cow <' a, str >) ;
222245
223246#[ cfg( __unicase__iter_cmp) ]
224247impl < T : AsRef < str > > PartialOrd for UniCase < T > {
@@ -306,7 +329,7 @@ mod tests {
306329 #[ cfg( feature = "nightly" ) ]
307330 #[ inline( never) ]
308331 fn is_ascii ( bytes : & [ u8 ] ) -> bool {
309- #[ allow( unused) ]
332+ #[ allow( unused, deprecated ) ]
310333 use std:: ascii:: AsciiExt ;
311334 bytes. is_ascii ( )
312335 }
0 commit comments