@@ -6,6 +6,8 @@ pub extern crate compact_str;
6
6
7
7
pub mod features;
8
8
9
+ #[ cfg( feature = "compact" ) ]
10
+ use compact_str:: CompactString ;
9
11
/// case-insensitive string handling
10
12
#[ cfg( not( feature = "compact" ) ) ]
11
13
#[ derive( Debug , Clone , Default ) ]
@@ -16,65 +18,7 @@ pub struct CaseInsensitiveString(String);
16
18
#[ cfg( feature = "compact" ) ]
17
19
#[ derive( Debug , Clone , Default ) ]
18
20
#[ repr( transparent) ]
19
- pub struct CaseInsensitiveString ( compact_str:: CompactString ) ;
20
-
21
- impl PartialEq for CaseInsensitiveString {
22
- #[ inline]
23
- fn eq ( & self , other : & Self ) -> bool {
24
- self . 0 . eq_ignore_ascii_case ( & other. 0 )
25
- }
26
- }
27
-
28
- impl Eq for CaseInsensitiveString { }
29
-
30
- impl std:: hash:: Hash for CaseInsensitiveString {
31
- #[ inline]
32
- fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
33
- self . 0 . to_ascii_lowercase ( ) . hash ( state)
34
- }
35
- }
36
-
37
- impl From < & str > for CaseInsensitiveString {
38
- #[ inline]
39
- fn from ( s : & str ) -> Self {
40
- CaseInsensitiveString { 0 : s. into ( ) }
41
- }
42
- }
43
-
44
- #[ cfg( feature = "compact" ) ]
45
- impl From < compact_str:: CompactString > for CaseInsensitiveString {
46
- #[ inline]
47
- fn from ( s : compact_str:: CompactString ) -> Self {
48
- CaseInsensitiveString { 0 : s. into ( ) }
49
- }
50
- }
51
-
52
- impl From < String > for CaseInsensitiveString {
53
- fn from ( s : String ) -> Self {
54
- CaseInsensitiveString { 0 : s. into ( ) }
55
- }
56
- }
57
-
58
- impl From < & [ u8 ] > for CaseInsensitiveString {
59
- fn from ( s : & [ u8 ] ) -> Self {
60
- CaseInsensitiveString {
61
- 0 : String :: from_utf8_lossy ( s) . into ( ) ,
62
- }
63
- }
64
- }
65
-
66
- impl AsRef < str > for CaseInsensitiveString {
67
- #[ inline]
68
- fn as_ref ( & self ) -> & str {
69
- & self . 0
70
- }
71
- }
72
-
73
- impl core:: fmt:: Display for CaseInsensitiveString {
74
- fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
75
- write ! ( f, "{}" , self . 0 )
76
- }
77
- }
21
+ pub struct CaseInsensitiveString ( CompactString ) ;
78
22
79
23
impl CaseInsensitiveString {
80
24
/// Creates a `CaseInsensitiveString` slice from any byte slice.
@@ -112,7 +56,7 @@ impl CaseInsensitiveString {
112
56
113
57
#[ cfg( feature = "compact" ) ]
114
58
#[ inline]
115
- pub fn inner ( & self ) -> & compact_str :: CompactString {
59
+ pub fn inner ( & self ) -> & CompactString {
116
60
& self . 0
117
61
}
118
62
@@ -231,3 +175,150 @@ impl CaseInsensitiveString {
231
175
self . len ( ) == 0
232
176
}
233
177
}
178
+
179
+ impl Eq for CaseInsensitiveString { }
180
+
181
+ impl std:: hash:: Hash for CaseInsensitiveString {
182
+ #[ inline]
183
+ fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
184
+ self . 0 . to_ascii_lowercase ( ) . hash ( state)
185
+ }
186
+ }
187
+
188
+ impl From < & str > for CaseInsensitiveString {
189
+ #[ inline]
190
+ fn from ( s : & str ) -> Self {
191
+ CaseInsensitiveString { 0 : s. into ( ) }
192
+ }
193
+ }
194
+
195
+ #[ cfg( feature = "compact" ) ]
196
+ impl From < CompactString > for CaseInsensitiveString {
197
+ #[ inline]
198
+ fn from ( s : CompactString ) -> Self {
199
+ CaseInsensitiveString { 0 : s. into ( ) }
200
+ }
201
+ }
202
+
203
+ impl From < String > for CaseInsensitiveString {
204
+ fn from ( s : String ) -> Self {
205
+ CaseInsensitiveString { 0 : s. into ( ) }
206
+ }
207
+ }
208
+
209
+ impl From < & [ u8 ] > for CaseInsensitiveString {
210
+ fn from ( s : & [ u8 ] ) -> Self {
211
+ CaseInsensitiveString {
212
+ 0 : String :: from_utf8_lossy ( s) . into ( ) ,
213
+ }
214
+ }
215
+ }
216
+
217
+ impl AsRef < str > for CaseInsensitiveString {
218
+ #[ inline]
219
+ fn as_ref ( & self ) -> & str {
220
+ & self . 0
221
+ }
222
+ }
223
+
224
+ impl core:: fmt:: Display for CaseInsensitiveString {
225
+ fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> core:: fmt:: Result {
226
+ write ! ( f, "{}" , self . 0 )
227
+ }
228
+ }
229
+
230
+ impl std:: ops:: Deref for CaseInsensitiveString {
231
+ type Target = str ;
232
+
233
+ #[ inline]
234
+ fn deref ( & self ) -> & str {
235
+ & self . 0 . as_str ( )
236
+ }
237
+ }
238
+
239
+ impl std:: borrow:: Borrow < str > for CaseInsensitiveString {
240
+ #[ inline]
241
+ fn borrow ( & self ) -> & str {
242
+ & self . 0 . as_str ( )
243
+ }
244
+ }
245
+
246
+ impl PartialEq for CaseInsensitiveString {
247
+ #[ inline]
248
+ fn eq ( & self , other : & Self ) -> bool {
249
+ self . 0 . eq_ignore_ascii_case ( & other. 0 )
250
+ }
251
+ }
252
+
253
+ #[ cfg( feature = "compact" ) ]
254
+ impl PartialEq < CaseInsensitiveString > for & CompactString {
255
+ fn eq ( & self , other : & CaseInsensitiveString ) -> bool {
256
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
257
+ }
258
+ }
259
+
260
+ impl PartialEq < CaseInsensitiveString > for String {
261
+ fn eq ( & self , other : & CaseInsensitiveString ) -> bool {
262
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
263
+ }
264
+ }
265
+
266
+ impl < ' a > PartialEq < & ' a CaseInsensitiveString > for String {
267
+ fn eq ( & self , other : & & CaseInsensitiveString ) -> bool {
268
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
269
+ }
270
+ }
271
+
272
+ impl PartialEq < CaseInsensitiveString > for & String {
273
+ fn eq ( & self , other : & CaseInsensitiveString ) -> bool {
274
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
275
+ }
276
+ }
277
+
278
+ impl PartialEq < CaseInsensitiveString > for str {
279
+ fn eq ( & self , other : & CaseInsensitiveString ) -> bool {
280
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
281
+ }
282
+ }
283
+
284
+ impl < ' a > PartialEq < & ' a CaseInsensitiveString > for str {
285
+ fn eq ( & self , other : & & CaseInsensitiveString ) -> bool {
286
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
287
+ }
288
+ }
289
+
290
+ impl PartialEq < CaseInsensitiveString > for & str {
291
+ fn eq ( & self , other : & CaseInsensitiveString ) -> bool {
292
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
293
+ }
294
+ }
295
+
296
+ impl PartialEq < CaseInsensitiveString > for & & str {
297
+ fn eq ( & self , other : & CaseInsensitiveString ) -> bool {
298
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
299
+ }
300
+ }
301
+
302
+ impl < ' a > PartialEq < CaseInsensitiveString > for std:: borrow:: Cow < ' a , str > {
303
+ fn eq ( & self , other : & CaseInsensitiveString ) -> bool {
304
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
305
+ }
306
+ }
307
+
308
+ impl < ' a > PartialEq < CaseInsensitiveString > for & std:: borrow:: Cow < ' a , str > {
309
+ fn eq ( & self , other : & CaseInsensitiveString ) -> bool {
310
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
311
+ }
312
+ }
313
+
314
+ impl PartialEq < String > for & CaseInsensitiveString {
315
+ fn eq ( & self , other : & String ) -> bool {
316
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
317
+ }
318
+ }
319
+
320
+ impl < ' a > PartialEq < std:: borrow:: Cow < ' a , str > > for & CaseInsensitiveString {
321
+ fn eq ( & self , other : & std:: borrow:: Cow < ' a , str > ) -> bool {
322
+ self . eq_ignore_ascii_case ( & other. as_ref ( ) )
323
+ }
324
+ }
0 commit comments