aboutsummaryrefslogtreecommitdiff
path: root/src/filters
diff options
context:
space:
mode:
Diffstat (limited to 'src/filters')
-rw-r--r--src/filters/log.rs12
-rw-r--r--src/filters/mod.rs22
-rw-r--r--src/filters/player.rs1
3 files changed, 33 insertions, 2 deletions
diff --git a/src/filters/log.rs b/src/filters/log.rs
index ded4c44..8b84bf3 100644
--- a/src/filters/log.rs
+++ b/src/filters/log.rs
@@ -47,6 +47,18 @@ impl OutcomeFilter {
pub fn new(outcomes: HashSet<FightOutcome>) -> Box<dyn LogFilter> {
Box::new(OutcomeFilter(outcomes))
}
+
+ pub fn success() -> Box<dyn LogFilter> {
+ let mut outcomes = HashSet::new();
+ outcomes.insert(FightOutcome::Success);
+ Self::new(outcomes)
+ }
+
+ pub fn wipe() -> Box<dyn LogFilter> {
+ let mut outcomes = HashSet::new();
+ outcomes.insert(FightOutcome::Wipe);
+ Self::new(outcomes)
+ }
}
impl Filter<PartialEvtc, LogResult> for OutcomeFilter {
diff --git a/src/filters/mod.rs b/src/filters/mod.rs
index 62dc04b..525ff27 100644
--- a/src/filters/mod.rs
+++ b/src/filters/mod.rs
@@ -1,5 +1,5 @@
#![allow(clippy::new_ret_no_self)]
-use std::ops;
+use std::{ops, fmt};
use num_derive::FromPrimitive;
use num_traits::FromPrimitive as _;
@@ -59,7 +59,7 @@ impl From<bool> for Inclusion {
/// The main filter trait.
///
/// Filters are usually handled as a `Box<dyn Filter>`.
-pub trait Filter<Early, Late>: Send + Sync {
+pub trait Filter<Early, Late>: Send + Sync + fmt::Debug {
/// Determine early (before processing all events) whether the log stands a chance to be
/// included.
///
@@ -118,6 +118,12 @@ impl<E: 'static, L: 'static> ops::BitAnd<Box<dyn Filter<E, L>>> for Box<dyn Filt
}
}
+impl<E, L> fmt::Debug for AndFilter<E, L> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "({:?}) and ({:?})", self.0, self.1)
+ }
+}
+
struct OrFilter<E, L>(Box<dyn Filter<E, L>>, Box<dyn Filter<E, L>>);
impl<E, L> Filter<E, L> for OrFilter<E, L> {
@@ -144,6 +150,12 @@ impl<E: 'static, L: 'static> ops::BitOr<Box<dyn Filter<E, L>>> for Box<dyn Filte
}
}
+impl<E, L> fmt::Debug for OrFilter<E, L> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "({:?}) or ({:?})", self.0, self.1)
+ }
+}
+
struct NotFilter<E, L>(Box<dyn Filter<E, L>>);
impl<E, L> Filter<E, L> for NotFilter<E, L> {
@@ -164,6 +176,12 @@ impl<E: 'static, L: 'static> ops::Not for Box<dyn Filter<E, L>> {
}
}
+impl<E, L> fmt::Debug for NotFilter<E, L> {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "not ({:?})", self.0)
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/src/filters/player.rs b/src/filters/player.rs
index 6cc7713..8f9196a 100644
--- a/src/filters/player.rs
+++ b/src/filters/player.rs
@@ -20,6 +20,7 @@ pub trait PlayerFilter = Filter<Agent, Player>;
/// [`LogFilter`](../log/traitalias.LogFilter.html) by requiring all players to match.
///
/// This struct will short-circuit once the result is known.
+#[derive(Debug)]
struct AllPlayers(Box<dyn PlayerFilter>);
impl Filter<PartialEvtc, LogResult> for AllPlayers {