11use std:: borrow:: Borrow ;
22use std:: fmt:: { Display , Formatter , Result } ;
33use std:: hash:: { Hash , Hasher } ;
4- use std:: ops:: Deref ;
54
65/// A case-insensitive string that preserves the original case.
76///
@@ -36,18 +35,6 @@ impl From<&str> for CiString {
3635 }
3736}
3837
39- impl AsRef < str > for CiString {
40- fn as_ref ( & self ) -> & str {
41- & self . 0
42- }
43- }
44-
45- impl Display for CiString {
46- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
47- self . 0 . fmt ( f)
48- }
49- }
50-
5138impl PartialEq for CiString {
5239 fn eq ( & self , other : & Self ) -> bool {
5340 self . 0 . eq_ignore_ascii_case ( & other. 0 )
@@ -79,6 +66,18 @@ impl Borrow<CiStr> for CiString {
7966 }
8067}
8168
69+ impl AsRef < str > for CiString {
70+ fn as_ref ( & self ) -> & str {
71+ & self . 0
72+ }
73+ }
74+
75+ impl Display for CiString {
76+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
77+ self . 0 . fmt ( f)
78+ }
79+ }
80+
8281/// A case-insensitive borrowed string slice.
8382///
8483/// This is the borrowed equivalent of [`CiString`], allowing zero-cost
@@ -95,20 +94,6 @@ impl CiStr {
9594 }
9695}
9796
98- impl Deref for CiStr {
99- type Target = str ;
100-
101- fn deref ( & self ) -> & str {
102- & self . 0
103- }
104- }
105-
106- impl AsRef < str > for CiStr {
107- fn as_ref ( & self ) -> & str {
108- & self . 0
109- }
110- }
111-
11297impl PartialEq for CiStr {
11398 fn eq ( & self , other : & Self ) -> bool {
11499 self . 0 . eq_ignore_ascii_case ( & other. 0 )
@@ -128,6 +113,24 @@ impl Hash for CiStr {
128113 }
129114}
130115
116+ impl Borrow < str > for CiStr {
117+ fn borrow ( & self ) -> & str {
118+ & self . 0
119+ }
120+ }
121+
122+ impl AsRef < str > for CiStr {
123+ fn as_ref ( & self ) -> & str {
124+ & self . 0
125+ }
126+ }
127+
128+ impl Display for CiStr {
129+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
130+ self . 0 . fmt ( f)
131+ }
132+ }
133+
131134#[ cfg( test) ]
132135mod tests {
133136 use super :: * ;
@@ -230,15 +233,15 @@ mod tests {
230233
231234 #[ test]
232235 fn cistr_borrow ( ) {
233- let s = CiString :: from ( "Hello" . to_string ( ) ) ;
234- let borrowed: & CiStr = s. borrow ( ) ;
235- assert_eq ! ( borrowed. as_ref( ) , "Hello" ) ;
236+ let s = CiStr :: new ( "Hello" ) ;
237+ assert_eq ! ( s. as_ref( ) , "Hello" ) ;
238+ let b: & str = s. borrow ( ) ;
239+ assert_eq ! ( b, "Hello" ) ;
236240 }
237241
238242 #[ test]
239- fn cistr_deref ( ) {
240- let s = CiStr :: new ( "abc" ) ;
241- let s: & str = s. borrow ( ) ;
242- assert_eq ! ( s, "abc" ) ;
243+ fn cistr_display ( ) {
244+ let s = CiStr :: new ( "HeLLo" ) ;
245+ assert_eq ! ( format!( "{}" , s) , "HeLLo" ) ;
243246 }
244247}
0 commit comments