mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
[Service] Removed Filters and SearchFilters lifetimes and changed str instances to String
This commit is contained in:
parent
a8e2b51dbb
commit
f843780469
2 changed files with 24 additions and 22 deletions
|
|
@ -7,7 +7,9 @@ Protocols:
|
||||||
1. Added standard and serde derives to `GatheringSettings`.
|
1. Added standard and serde derives to `GatheringSettings`.
|
||||||
|
|
||||||
### Breaking:
|
### 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<String>`
|
||||||
|
|
||||||
# 0.2.2 - 01/05/2023
|
# 0.2.2 - 01/05/2023
|
||||||
### Changes:
|
### Changes:
|
||||||
|
|
|
||||||
|
|
@ -2,39 +2,39 @@ use std::collections::HashMap;
|
||||||
use std::mem::Discriminant;
|
use std::mem::Discriminant;
|
||||||
|
|
||||||
/// A query filter.
|
/// A query filter.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub enum Filter<'a> {
|
pub enum Filter {
|
||||||
IsSecured(bool),
|
IsSecured(bool),
|
||||||
RunsMap(&'a str),
|
RunsMap(String),
|
||||||
CanHavePassword(bool),
|
CanHavePassword(bool),
|
||||||
CanBeEmpty(bool),
|
CanBeEmpty(bool),
|
||||||
IsEmpty(bool),
|
IsEmpty(bool),
|
||||||
CanBeFull(bool),
|
CanBeFull(bool),
|
||||||
RunsAppID(u32),
|
RunsAppID(u32),
|
||||||
NotAppID(u32),
|
NotAppID(u32),
|
||||||
HasTags(&'a [&'a str]),
|
HasTags(Vec<String>),
|
||||||
MatchName(&'a str),
|
MatchName(String),
|
||||||
MatchVersion(&'a str),
|
MatchVersion(String),
|
||||||
/// Restrict to only a server if an IP hosts (on different ports) multiple servers.
|
/// Restrict to only a server if an IP hosts (on different ports) multiple servers.
|
||||||
RestrictUniqueIP(bool),
|
RestrictUniqueIP(bool),
|
||||||
/// Query for servers on a specific address.
|
/// Query for servers on a specific address.
|
||||||
OnAddress(&'a str),
|
OnAddress(String),
|
||||||
Whitelisted(bool),
|
Whitelisted(bool),
|
||||||
SpectatorProxy(bool),
|
SpectatorProxy(bool),
|
||||||
IsDedicated(bool),
|
IsDedicated(bool),
|
||||||
RunsLinux(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 {
|
match b {
|
||||||
true => b'1',
|
true => b'1',
|
||||||
false => b'0',
|
false => b'0',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Filter<'a> {
|
impl Filter {
|
||||||
pub(crate) fn to_bytes(self) -> Vec<u8> {
|
pub(crate) fn to_bytes(&self) -> Vec<u8> {
|
||||||
let mut bytes: Vec<u8> = Vec::new();
|
let mut bytes: Vec<u8> = Vec::new();
|
||||||
|
|
||||||
match self {
|
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.
|
/// 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)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct SearchFilters<'a> {
|
pub struct SearchFilters {
|
||||||
filters: HashMap<Discriminant<Filter<'a>>, Filter<'a>>,
|
filters: HashMap<Discriminant<Filter>, Filter>,
|
||||||
nor_filters: HashMap<Discriminant<Filter<'a>>, Filter<'a>>,
|
nor_filters: HashMap<Discriminant<Filter>, Filter>,
|
||||||
nand_filters: HashMap<Discriminant<Filter<'a>>, Filter<'a>>,
|
nand_filters: HashMap<Discriminant<Filter>, Filter>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Default for SearchFilters<'a> {
|
impl Default for SearchFilters {
|
||||||
fn default() -> Self { SearchFilters::new() }
|
fn default() -> Self { SearchFilters::new() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SearchFilters<'a> {
|
impl SearchFilters {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
filters: HashMap::new(),
|
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;
|
let mut updated_fitler = self.filters;
|
||||||
updated_fitler.insert(std::mem::discriminant(&filter), filter);
|
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;
|
let mut updated_fitler = self.nor_filters;
|
||||||
updated_fitler.insert(std::mem::discriminant(&filter), filter);
|
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;
|
let mut updated_fitler = self.nand_filters;
|
||||||
updated_fitler.insert(std::mem::discriminant(&filter), filter);
|
updated_fitler.insert(std::mem::discriminant(&filter), filter);
|
||||||
|
|
||||||
|
|
@ -194,7 +194,7 @@ impl<'a> SearchFilters<'a> {
|
||||||
bytes.extend(name.as_bytes());
|
bytes.extend(name.as_bytes());
|
||||||
bytes.extend(filters.len().to_string().as_bytes());
|
bytes.extend(filters.len().to_string().as_bytes());
|
||||||
for filter in filters.values() {
|
for filter in filters.values() {
|
||||||
bytes.extend(filter.to_bytes())
|
bytes.extend(filter.to_bytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue