rust/clippy: fix lint: manual_find

These get_tx methods look like ideal candidates for generic and/or
derived methods.
pull/8251/head
Jason Ish 4 years ago committed by Victor Julien
parent 4940dfb3bd
commit 029ac650d7

@ -103,12 +103,7 @@ impl TemplateState {
} }
pub fn get_tx(&mut self, tx_id: u64) -> Option<&TemplateTransaction> { pub fn get_tx(&mut self, tx_id: u64) -> Option<&TemplateTransaction> {
for tx in &mut self.transactions { self.transactions.iter().find(|tx| tx.tx_id == tx_id + 1)
if tx.tx_id == tx_id + 1 {
return Some(tx);
}
}
return None;
} }
fn new_tx(&mut self) -> TemplateTransaction { fn new_tx(&mut self) -> TemplateTransaction {
@ -119,12 +114,7 @@ impl TemplateState {
} }
fn find_request(&mut self) -> Option<&mut TemplateTransaction> { fn find_request(&mut self) -> Option<&mut TemplateTransaction> {
for tx in &mut self.transactions { self.transactions.iter_mut().find(|tx| tx.response.is_none())
if tx.response.is_none() {
return Some(tx);
}
}
None
} }
fn parse_request(&mut self, input: &[u8]) -> AppLayerResult { fn parse_request(&mut self, input: &[u8]) -> AppLayerResult {

@ -148,12 +148,7 @@ impl DHCPState {
} }
pub fn get_tx(&mut self, tx_id: u64) -> Option<&DHCPTransaction> { pub fn get_tx(&mut self, tx_id: u64) -> Option<&DHCPTransaction> {
for tx in &mut self.transactions { self.transactions.iter().find(|tx| tx.tx_id == tx_id + 1)
if tx.tx_id == tx_id + 1 {
return Some(tx);
}
}
return None;
} }
fn free_tx(&mut self, tx_id: u64) { fn free_tx(&mut self, tx_id: u64) {

@ -167,12 +167,7 @@ impl IKEState {
} }
pub fn get_tx(&mut self, tx_id: u64) -> Option<&mut IKETransaction> { pub fn get_tx(&mut self, tx_id: u64) -> Option<&mut IKETransaction> {
for tx in &mut self.transactions { self.transactions.iter_mut().find(|tx| tx.tx_id == tx_id + 1)
if tx.tx_id == tx_id + 1 {
return Some(tx);
}
}
return None;
} }
pub fn new_tx(&mut self) -> IKETransaction { pub fn new_tx(&mut self) -> IKETransaction {

@ -27,7 +27,6 @@
#![allow(clippy::too_many_arguments)] #![allow(clippy::too_many_arguments)]
// To be fixed, but remove the noise for now. // To be fixed, but remove the noise for now.
#![allow(clippy::manual_find)]
#![allow(clippy::match_like_matches_macro)] #![allow(clippy::match_like_matches_macro)]
#![allow(clippy::module_inception)] #![allow(clippy::module_inception)]
#![allow(clippy::result_unit_err)] #![allow(clippy::result_unit_err)]

@ -113,12 +113,7 @@ impl ModbusState {
} }
pub fn get_tx(&mut self, tx_id: u64) -> Option<&mut ModbusTransaction> { pub fn get_tx(&mut self, tx_id: u64) -> Option<&mut ModbusTransaction> {
for tx in &mut self.transactions { self.transactions.iter_mut().find(|tx| tx.id == tx_id + 1)
if tx.id == tx_id + 1 {
return Some(tx);
}
}
None
} }
/// Searches the requests in order to find one matching the given response. Returns the matching /// Searches the requests in order to find one matching the given response. Returns the matching

@ -158,12 +158,7 @@ impl MQTTState {
} }
pub fn get_tx(&mut self, tx_id: u64) -> Option<&MQTTTransaction> { pub fn get_tx(&mut self, tx_id: u64) -> Option<&MQTTTransaction> {
for tx in &mut self.transactions { self.transactions.iter().find(|tx| tx.tx_id == tx_id + 1)
if tx.tx_id == tx_id + 1 {
return Some(tx);
}
}
return None;
} }
pub fn get_tx_by_pkt_id(&mut self, pkt_id: u32) -> Option<&mut MQTTTransaction> { pub fn get_tx_by_pkt_id(&mut self, pkt_id: u32) -> Option<&mut MQTTTransaction> {

@ -187,12 +187,7 @@ impl PgsqlState {
} }
pub fn get_tx(&mut self, tx_id: u64) -> Option<&PgsqlTransaction> { pub fn get_tx(&mut self, tx_id: u64) -> Option<&PgsqlTransaction> {
for tx in &mut self.transactions { self.transactions.iter().find(|tx| tx.tx_id == tx_id + 1)
if tx.tx_id == tx_id + 1 {
return Some(tx);
}
}
return None;
} }
fn new_tx(&mut self) -> PgsqlTransaction { fn new_tx(&mut self) -> PgsqlTransaction {

@ -136,12 +136,7 @@ impl RFBState {
} }
pub fn get_tx(&mut self, tx_id: u64) -> Option<&RFBTransaction> { pub fn get_tx(&mut self, tx_id: u64) -> Option<&RFBTransaction> {
for tx in &mut self.transactions { self.transactions.iter().find(|tx| tx.tx_id == tx_id + 1)
if tx.tx_id == tx_id + 1 {
return Some(tx);
}
}
return None;
} }
fn new_tx(&mut self) -> RFBTransaction { fn new_tx(&mut self) -> RFBTransaction {
@ -152,12 +147,8 @@ impl RFBState {
} }
fn get_current_tx(&mut self) -> Option<&mut RFBTransaction> { fn get_current_tx(&mut self) -> Option<&mut RFBTransaction> {
for tx in &mut self.transactions { let tx_id = self.tx_id;
if tx.tx_id == self.tx_id { self.transactions.iter_mut().find(|tx| tx.tx_id == tx_id)
return Some(tx);
}
}
return None;
} }
fn parse_request(&mut self, input: &[u8]) -> AppLayerResult { fn parse_request(&mut self, input: &[u8]) -> AppLayerResult {

@ -131,12 +131,7 @@ impl TelnetState {
} }
pub fn get_tx(&mut self, tx_id: u64) -> Option<&TelnetTransaction> { pub fn get_tx(&mut self, tx_id: u64) -> Option<&TelnetTransaction> {
for tx in &mut self.transactions { self.transactions.iter().find(|tx| tx.tx_id == tx_id + 1)
if tx.tx_id == tx_id + 1 {
return Some(tx);
}
}
return None;
} }
fn _new_tx(&mut self) -> TelnetTransaction { fn _new_tx(&mut self) -> TelnetTransaction {

Loading…
Cancel
Save