perf: use of ok_or followed by a function call

This commit is contained in:
CosminPerRam 2023-12-11 03:53:18 +02:00
parent e1bffd2045
commit 9c3e6cb51f
3 changed files with 3 additions and 3 deletions

View file

@ -90,7 +90,7 @@ pub fn query_with_timeout(
let packets = client.get_server_packets()?;
let data = packets
.get(0)
.ok_or(PacketBad.context("First packet missing"))?;
.ok_or_else(|| PacketBad.context("First packet missing"))?;
let (mut server_vars, remaining_data) = data_to_map(data)?;
let players = parse_players_and_teams(&remaining_data)?;

View file

@ -4,7 +4,7 @@ use std::collections::HashMap;
pub fn has_password(server_vars: &mut HashMap<String, String>) -> GDResult<bool> {
let password_value = server_vars
.remove("password")
.ok_or(GDErrorKind::PacketBad.context("Missing password (exists) field"))?
.ok_or_else(|| GDErrorKind::PacketBad.context("Missing password (exists) field"))?
.to_lowercase();
if let Ok(has) = password_value.parse::<bool>() {

View file

@ -209,7 +209,7 @@ impl StringDecoder for Unreal2StringDecoder {
let mut ucs2 = false;
let mut length: usize = (*data
.first()
.ok_or(PacketBad.context("Tried to decode string without length"))?)
.ok_or_else(|| PacketBad.context("Tried to decode string without length"))?)
.into();
let mut start = 0;