mirror of
https://github.com/icewind1991/warp-real-ip.git
synced 2026-06-03 18:54:06 +02:00
clippy fixes
This commit is contained in:
parent
3f6837c87c
commit
b3b38b335b
1 changed files with 48 additions and 51 deletions
17
src/lib.rs
17
src/lib.rs
|
|
@ -41,7 +41,7 @@ pub fn real_ip(
|
|||
}
|
||||
|
||||
// all hops were trusted, return the last one
|
||||
forwarded_for.first().copied().unwrap_or(addr.ip())
|
||||
forwarded_for.first().copied().unwrap_or_else(|| addr.ip())
|
||||
})
|
||||
},
|
||||
)
|
||||
|
|
@ -72,7 +72,7 @@ pub fn get_forwarded_for() -> impl Filter<Extract = (Vec<IpAddr>,), Error = Infa
|
|||
.collect::<Vec<_>>()
|
||||
}))
|
||||
.unify()
|
||||
.or(warp::any().map(|| vec![]))
|
||||
.or(warp::any().map(Vec::new))
|
||||
.unify()
|
||||
}
|
||||
|
||||
|
|
@ -110,9 +110,8 @@ impl<'a> Iterator for CommaSeparatedIterator<'a> {
|
|||
type Item = &'a str;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
loop {
|
||||
match self.char_indices.next() {
|
||||
Some((i, c)) => match match self.state {
|
||||
while let Some((i, c)) = self.char_indices.next() {
|
||||
match match self.state {
|
||||
CommaSeparatedIteratorState::Default => match c {
|
||||
'"' => {
|
||||
self.s = i;
|
||||
|
|
@ -158,11 +157,9 @@ impl<'a> Iterator for CommaSeparatedIterator<'a> {
|
|||
(None, next_state) => {
|
||||
self.state = next_state;
|
||||
}
|
||||
},
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
return match self.state {
|
||||
match self.state {
|
||||
CommaSeparatedIteratorState::Default
|
||||
| CommaSeparatedIteratorState::PostAmbleForQuoted => None,
|
||||
CommaSeparatedIteratorState::Quoted | CommaSeparatedIteratorState::QuotedPair => {
|
||||
|
|
@ -173,7 +170,7 @@ impl<'a> Iterator for CommaSeparatedIterator<'a> {
|
|||
self.state = CommaSeparatedIteratorState::Default;
|
||||
Some(&self.target[self.s..])
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +207,7 @@ fn maybe_quoted(x: &str) -> Cow<str> {
|
|||
}
|
||||
|
||||
fn maybe_bracketed(x: &str) -> &str {
|
||||
if x.as_bytes()[0] == ('[' as u8) && x.as_bytes()[x.len() - 1] == (']' as u8) {
|
||||
if x.as_bytes()[0] == (b'[') && x.as_bytes()[x.len() - 1] == (b']') {
|
||||
&x[1..x.len() - 1]
|
||||
} else {
|
||||
x
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue