diff options
author | Daniel <kingdread@gmx.de> | 2020-04-18 15:10:59 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2020-04-18 15:10:59 +0200 |
commit | 7030224fd2a97b3551fdd47c43249e3a42341238 (patch) | |
tree | e5986f57f186ab061db9030c5f10285c3eb6b6d7 | |
parent | 79752779036d31ee6427c731cd7c058eccf1034a (diff) | |
download | raidgrep-7030224fd2a97b3551fdd47c43249e3a42341238.tar.gz raidgrep-7030224fd2a97b3551fdd47c43249e3a42341238.tar.bz2 raidgrep-7030224fd2a97b3551fdd47c43249e3a42341238.zip |
make filters Debug
It's nice if you can print out the filter tree for debugging, so we're
requireing filters to be Debug now.
-rw-r--r-- | src/filters/log.rs | 12 | ||||
-rw-r--r-- | src/filters/mod.rs | 22 | ||||
-rw-r--r-- | src/filters/player.rs | 1 |
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 { |