aboutsummaryrefslogtreecommitdiff
path: root/src/csl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/csl.rs')
-rw-r--r--src/csl.rs34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/csl.rs b/src/csl.rs
index e7d84f3..ac20ada 100644
--- a/src/csl.rs
+++ b/src/csl.rs
@@ -1,14 +1,14 @@
use std::collections::HashSet;
+use std::fmt;
use std::hash::Hash;
use std::str::FromStr;
-use std::fmt;
-use super::{SearchField, FightOutcome};
+use super::{FightOutcome, SearchField};
use chrono::Weekday;
use evtclib::statistics::gamedata::Boss;
pub trait Variants: Copy {
- type Output: Iterator<Item=Self>;
+ type Output: Iterator<Item = Self>;
fn variants() -> Self::Output;
}
@@ -79,18 +79,21 @@ impl<E: fmt::Display> fmt::Display for ParseError<E> {
}
impl<T> FromStr for CommaSeparatedList<T>
- where T: FromStr + Variants + Hash + Eq + fmt::Debug
+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() })
+ 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()
+ values: all_values.difference(&no_csl.values).cloned().collect(),
})
} else {
let parts = input.split(DELIMITER);
@@ -104,9 +107,26 @@ impl<T> FromStr for CommaSeparatedList<T>
}
impl<T> CommaSeparatedList<T>
- where T: Hash + Eq + fmt::Debug
+where
+ T: Hash + Eq + fmt::Debug,
{
pub fn contains(&self, value: &T) -> bool {
self.values.contains(value)
}
+
+ pub fn values(&self) -> &HashSet<T> {
+ &self.values
+ }
+}
+
+// We allow implicit hasher because then it's a zero-cost conversion, as we're just unwrapping the
+// values.
+#[allow(clippy::implicit_hasher)]
+impl<T> From<CommaSeparatedList<T>> for HashSet<T>
+where
+ T: Hash + Eq + fmt::Debug,
+{
+ fn from(csl: CommaSeparatedList<T>) -> Self {
+ csl.values
+ }
}