Skip to content

Commit 6e156b7

Browse files
committed
feat(sys): impl Hash for ngx_str_t
Style fixes.
1 parent 17b18d9 commit 6e156b7

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

nginx-sys/src/string.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
use core::cmp;
12
use core::fmt;
3+
use core::hash;
24
use core::ptr;
35
use core::slice;
6+
use core::str;
47

58
use crate::bindings::{ngx_pool_t, ngx_str_t};
69
use 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+
113123
impl 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 {
135144
impl Eq for ngx_str_t {}
136145

137146
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> {
139148
Some(self.cmp(other))
140149
}
141150
}
142151

143152
impl 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

149158
impl 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

Comments
 (0)