1
+ use core:: cmp;
1
2
use core:: fmt;
3
+ use core:: hash;
2
4
use core:: ptr;
3
5
use core:: slice;
6
+ use core:: str;
4
7
5
8
use crate :: bindings:: { ngx_pool_t, ngx_str_t} ;
6
9
use crate :: detail;
@@ -45,7 +48,7 @@ impl ngx_str_t {
45
48
/// # Returns
46
49
/// A string slice (`&str`) representing the nginx string.
47
50
pub fn to_str ( & self ) -> & str {
48
- core :: str:: from_utf8 ( self . as_bytes ( ) ) . unwrap ( )
51
+ str:: from_utf8 ( self . as_bytes ( ) ) . unwrap ( )
49
52
}
50
53
51
54
/// Creates an empty `ngx_str_t` instance.
@@ -110,6 +113,13 @@ impl Default for ngx_str_t {
110
113
}
111
114
}
112
115
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
+
113
123
impl From < ngx_str_t > for & [ u8 ] {
114
124
fn from ( s : ngx_str_t ) -> Self {
115
125
if s. len == 0 || s. data . is_null ( ) {
@@ -119,10 +129,9 @@ impl From<ngx_str_t> for &[u8] {
119
129
}
120
130
}
121
131
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)
126
135
}
127
136
}
128
137
@@ -135,21 +144,21 @@ impl PartialEq for ngx_str_t {
135
144
impl Eq for ngx_str_t { }
136
145
137
146
impl 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 > {
139
148
Some ( self . cmp ( other) )
140
149
}
141
150
}
142
151
143
152
impl Ord for ngx_str_t {
144
- fn cmp ( & self , other : & Self ) -> core :: cmp:: Ordering {
153
+ fn cmp ( & self , other : & Self ) -> cmp:: Ordering {
145
154
Ord :: cmp ( self . as_bytes ( ) , other. as_bytes ( ) )
146
155
}
147
156
}
148
157
149
158
impl TryFrom < ngx_str_t > for & str {
150
- type Error = core :: str:: Utf8Error ;
159
+ type Error = str:: Utf8Error ;
151
160
152
161
fn try_from ( s : ngx_str_t ) -> Result < Self , Self :: Error > {
153
- core :: str:: from_utf8 ( s. into ( ) )
162
+ str:: from_utf8 ( s. into ( ) )
154
163
}
155
164
}
0 commit comments