diff options
author | Daniel <kingdread@gmx.de> | 2020-04-26 11:45:37 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2020-04-26 11:45:37 +0200 |
commit | 13053073e3336b8e6ffefd6a056d159239550be7 (patch) | |
tree | 63544e8764b55563a48d3f9fd530b0381f42a277 /src/csl.rs | |
parent | 3c429432382dfad6d4ac97349c96e4a4eb292089 (diff) | |
parent | 9bbd5db2a6caae10f0ab2cf2625fbc34485a4ce9 (diff) | |
download | raidgrep-13053073e3336b8e6ffefd6a056d159239550be7.tar.gz raidgrep-13053073e3336b8e6ffefd6a056d159239550be7.tar.bz2 raidgrep-13053073e3336b8e6ffefd6a056d159239550be7.zip |
Merge branch 'new-filters'
The new filter system (includes both the internal rewrite and the
command line parsing) is now being included in master. This gives a lot
more flexibility.
Diffstat (limited to 'src/csl.rs')
-rw-r--r-- | src/csl.rs | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/src/csl.rs b/src/csl.rs deleted file mode 100644 index e7d84f3..0000000 --- a/src/csl.rs +++ /dev/null @@ -1,112 +0,0 @@ -use std::collections::HashSet; -use std::hash::Hash; -use std::str::FromStr; -use std::fmt; - -use super::{SearchField, FightOutcome}; -use chrono::Weekday; -use evtclib::statistics::gamedata::Boss; - -pub trait Variants: Copy { - type Output: Iterator<Item=Self>; - fn variants() -> Self::Output; -} - -macro_rules! variants { - ($target:ident => $($var:ident),+) => { - impl Variants for $target { - type Output = ::std::iter::Cloned<::std::slice::Iter<'static, Self>>; - fn variants() -> Self::Output { - // Exhaustiveness check - #[allow(dead_code)] - fn exhaustiveness_check(value: $target) { - match value { - $($target :: $var => ()),+ - } - } - // Actual result - [ - $($target :: $var),+ - ].iter().cloned() - } - } - }; - ($target:ident => $($var:ident,)+) => { - variants!($target => $($var),+); - }; -} - -variants! { SearchField => Account, Character, Guild } -variants! { FightOutcome => Success, Wipe } -variants! { Weekday => Mon, Tue, Wed, Thu, Fri, Sat, Sun } -variants! { Boss => - ValeGuardian, Gorseval, Sabetha, - Slothasor, Matthias, - KeepConstruct, Xera, - Cairn, MursaatOverseer, Samarog, Deimos, - SoullessHorror, Dhuum, - ConjuredAmalgamate, LargosTwins, Qadim, - CardinalAdina, CardinalSabir, QadimThePeerless, - - IcebroodConstruct, VoiceOfTheFallen, FraenirOfJormag, Boneskinner, WhisperOfJormag, - - Skorvald, Artsariiv, Arkk, - MAMA, Siax, Ensolyss, -} - -/// The character that delimits items from each other. -const DELIMITER: char = ','; -/// The character that negates the result. -const NEGATOR: char = '!'; - -/// A list that is given as comma-separated values. -#[derive(Debug, Clone)] -pub struct CommaSeparatedList<T: Eq + Hash + fmt::Debug> { - values: HashSet<T>, -} - -#[derive(Debug, Clone)] -pub enum ParseError<E> { - Underlying(E), -} - -impl<E: fmt::Display> fmt::Display for ParseError<E> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - ParseError::Underlying(ref e) => e.fmt(f), - } - } -} - -impl<T> FromStr for CommaSeparatedList<T> - where T: FromStr + Variants + Hash + Eq + fmt::Debug -{ - type Err = ParseError<T::Err>; - - fn from_str(input: &str) -> Result<Self, Self::Err> { - if input == "*" { - Ok(CommaSeparatedList { values: T::variants().collect() }) - } else if input.starts_with(NEGATOR) { - let no_csl = CommaSeparatedList::from_str(&input[1..])?; - let all_values = T::variants().collect::<HashSet<_>>(); - Ok(CommaSeparatedList { - values: all_values.difference(&no_csl.values).cloned().collect() - }) - } else { - let parts = input.split(DELIMITER); - let values = parts - .map(FromStr::from_str) - .collect::<Result<HashSet<_>, _>>() - .map_err(ParseError::Underlying)?; - Ok(CommaSeparatedList { values }) - } - } -} - -impl<T> CommaSeparatedList<T> - where T: Hash + Eq + fmt::Debug -{ - pub fn contains(&self, value: &T) -> bool { - self.values.contains(value) - } -} |