From f8437804696f9635c3314bbcbd9ede95b41bf9a2 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Mon, 8 May 2023 15:31:38 +0300 Subject: [PATCH] [Service] Removed Filters and SearchFilters lifetimes and changed str instances to String --- CHANGELOG.md | 4 ++- src/services/valve_master_server/types.rs | 42 +++++++++++------------ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3243676..f65ad09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ Protocols: 1. Added standard and serde derives to `GatheringSettings`. ### Breaking: -Nothing, yet... +Services: +- Valve Master Query: +1. Removed Filter and SearchFilters lifetimes and changed `&'a str` to `String` and `&'a [&'a str]` to `Vec` # 0.2.2 - 01/05/2023 ### Changes: diff --git a/src/services/valve_master_server/types.rs b/src/services/valve_master_server/types.rs index 4a3d2d9..0bcd672 100644 --- a/src/services/valve_master_server/types.rs +++ b/src/services/valve_master_server/types.rs @@ -2,39 +2,39 @@ use std::collections::HashMap; use std::mem::Discriminant; /// A query filter. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -pub enum Filter<'a> { +#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] +pub enum Filter { IsSecured(bool), - RunsMap(&'a str), + RunsMap(String), CanHavePassword(bool), CanBeEmpty(bool), IsEmpty(bool), CanBeFull(bool), RunsAppID(u32), NotAppID(u32), - HasTags(&'a [&'a str]), - MatchName(&'a str), - MatchVersion(&'a str), + HasTags(Vec), + MatchName(String), + MatchVersion(String), /// Restrict to only a server if an IP hosts (on different ports) multiple servers. RestrictUniqueIP(bool), /// Query for servers on a specific address. - OnAddress(&'a str), + OnAddress(String), Whitelisted(bool), SpectatorProxy(bool), IsDedicated(bool), RunsLinux(bool), - HasGameDir(&'a str), + HasGameDir(String), } -fn bool_as_char_u8(b: bool) -> u8 { +fn bool_as_char_u8(b: &bool) -> u8 { match b { true => b'1', false => b'0', } } -impl<'a> Filter<'a> { - pub(crate) fn to_bytes(self) -> Vec { +impl Filter { + pub(crate) fn to_bytes(&self) -> Vec { let mut bytes: Vec = Vec::new(); match self { @@ -135,17 +135,17 @@ impl<'a> Filter<'a> { /// ``` /// This will construct filters that search for servers that can't have a password, are not empty and run App ID 440. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct SearchFilters<'a> { - filters: HashMap>, Filter<'a>>, - nor_filters: HashMap>, Filter<'a>>, - nand_filters: HashMap>, Filter<'a>>, +pub struct SearchFilters { + filters: HashMap, Filter>, + nor_filters: HashMap, Filter>, + nand_filters: HashMap, Filter>, } -impl<'a> Default for SearchFilters<'a> { +impl Default for SearchFilters { fn default() -> Self { SearchFilters::new() } } -impl<'a> SearchFilters<'a> { +impl SearchFilters { pub fn new() -> Self { Self { filters: HashMap::new(), @@ -154,7 +154,7 @@ impl<'a> SearchFilters<'a> { } } - pub fn insert(self, filter: Filter<'a>) -> Self { + pub fn insert(self, filter: Filter) -> Self { let mut updated_fitler = self.filters; updated_fitler.insert(std::mem::discriminant(&filter), filter); @@ -165,7 +165,7 @@ impl<'a> SearchFilters<'a> { } } - pub fn insert_nand(self, filter: Filter<'a>) -> Self { + pub fn insert_nand(self, filter: Filter) -> Self { let mut updated_fitler = self.nor_filters; updated_fitler.insert(std::mem::discriminant(&filter), filter); @@ -176,7 +176,7 @@ impl<'a> SearchFilters<'a> { } } - pub fn insert_nor(self, filter: Filter<'a>) -> Self { + pub fn insert_nor(self, filter: Filter) -> Self { let mut updated_fitler = self.nand_filters; updated_fitler.insert(std::mem::discriminant(&filter), filter); @@ -194,7 +194,7 @@ impl<'a> SearchFilters<'a> { bytes.extend(name.as_bytes()); bytes.extend(filters.len().to_string().as_bytes()); for filter in filters.values() { - bytes.extend(filter.to_bytes()) + bytes.extend(filter.to_bytes()); } }