1+ use core:: cmp;
12use core:: fmt;
3+ use core:: hash;
24use core:: ptr;
35use core:: slice;
6+ use core:: str;
47
58use crate :: bindings:: { ngx_pool_t, ngx_str_t} ;
69use crate :: detail;
@@ -45,7 +48,7 @@ impl ngx_str_t {
4548 /// # Returns
4649 /// A string slice (`&str`) representing the nginx string.
4750 pub fn to_str ( & self ) -> & str {
48- core :: str:: from_utf8 ( self . as_bytes ( ) ) . unwrap ( )
51+ str:: from_utf8 ( self . as_bytes ( ) ) . unwrap ( )
4952 }
5053
5154 /// Creates an empty `ngx_str_t` instance.
@@ -110,6 +113,13 @@ impl Default for ngx_str_t {
110113 }
111114}
112115
116+ impl fmt:: Display for ngx_str_t {
117+ #[ inline]
118+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
119+ detail:: display_bytes ( f, self . as_bytes ( ) )
120+ }
121+ }
122+
113123impl From < ngx_str_t > for & [ u8 ] {
114124 fn from ( s : ngx_str_t ) -> Self {
115125 if s. len == 0 || s. data . is_null ( ) {
@@ -119,10 +129,9 @@ impl From<ngx_str_t> for &[u8] {
119129 }
120130}
121131
122- impl fmt:: Display for ngx_str_t {
123- #[ inline]
124- fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
125- detail:: display_bytes ( f, self . as_bytes ( ) )
132+ impl hash:: Hash for ngx_str_t {
133+ fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
134+ self . as_bytes ( ) . hash ( state)
126135 }
127136}
128137
@@ -135,21 +144,21 @@ impl PartialEq for ngx_str_t {
135144impl Eq for ngx_str_t { }
136145
137146impl PartialOrd < Self > for ngx_str_t {
138- fn partial_cmp ( & self , other : & Self ) -> Option < core :: cmp:: Ordering > {
147+ fn partial_cmp ( & self , other : & Self ) -> Option < cmp:: Ordering > {
139148 Some ( self . cmp ( other) )
140149 }
141150}
142151
143152impl Ord for ngx_str_t {
144- fn cmp ( & self , other : & Self ) -> core :: cmp:: Ordering {
153+ fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
145154 Ord :: cmp ( self . as_bytes ( ) , other. as_bytes ( ) )
146155 }
147156}
148157
149158impl TryFrom < ngx_str_t > for & str {
150- type Error = core :: str:: Utf8Error ;
159+ type Error = str:: Utf8Error ;
151160
152161 fn try_from ( s : ngx_str_t ) -> Result < Self , Self :: Error > {
153- core :: str:: from_utf8 ( s. into ( ) )
162+ str:: from_utf8 ( s. into ( ) )
154163 }
155164}
0 commit comments