From c5fd58f794120b8de4ea092c19ac5702d41a22c4 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Fri, 28 Apr 2023 19:09:11 +0300 Subject: [PATCH] [Protocol] Some cargo clippy improvements for GS one and three --- src/protocols/gamespy/protocols/one/protocol.rs | 2 +- src/protocols/gamespy/protocols/three/protocol.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/protocols/gamespy/protocols/one/protocol.rs b/src/protocols/gamespy/protocols/one/protocol.rs index 5a6d87e..4d32fe1 100644 --- a/src/protocols/gamespy/protocols/one/protocol.rs +++ b/src/protocols/gamespy/protocols/one/protocol.rs @@ -219,7 +219,7 @@ pub fn query(address: &str, port: u16, timeout_settings: Option players, tournament: server_vars .remove("tournament") - .unwrap_or("true".to_string()) + .unwrap_or_else(|| "true".to_string()) .to_lowercase() .parse() .map_err(|_| GDError::TypeParse)?, diff --git a/src/protocols/gamespy/protocols/three/protocol.rs b/src/protocols/gamespy/protocols/three/protocol.rs index c834d97..fdd0305 100644 --- a/src/protocols/gamespy/protocols/three/protocol.rs +++ b/src/protocols/gamespy/protocols/three/protocol.rs @@ -18,7 +18,7 @@ struct RequestPacket { } impl RequestPacket { - fn to_bytes(self) -> Vec { + fn to_bytes(&self) -> Vec { let mut packet: Vec = Vec::with_capacity(7); packet.extend_from_slice(&self.header.to_be_bytes()); packet.push(self.kind); @@ -144,10 +144,10 @@ fn get_server_packets(address: &str, port: u16, timeout_settings: Option) -> GDResult<(HashMap, Vec)> { +fn data_to_map(packet: &[u8]) -> GDResult<(HashMap, Vec)> { let mut vars = HashMap::new(); - let mut buf = Bufferer::new_with_data(Endianess::Big, &packet); + let mut buf = Bufferer::new_with_data(Endianess::Big, packet); while buf.remaining_length() > 0 { let key = buf.get_string_utf8()?; if key.is_empty() { @@ -201,7 +201,7 @@ fn parse_players_and_teams(packets: Vec>) -> GDResult<(Vec, Vec< } let field_split: Vec<&str> = field.split('_').collect(); - let field_name = field_split.get(0).ok_or(GDError::PacketBad)?; + let field_name = field_split.first().ok_or(GDError::PacketBad)?; if !["player", "score", "ping", "team", "deaths", "pid", "skill"].contains(field_name) { continue; } @@ -342,7 +342,7 @@ pub fn query(address: &str, port: u16, timeout_settings: Option teams, tournament: server_vars .remove("tournament") - .unwrap_or("true".to_string()) + .unwrap_or_else(|| "true".to_string()) .to_lowercase() .parse() .map_err(|_| GDError::TypeParse)?,