aboutsummaryrefslogtreecommitdiff
path: root/src/filters/mod.rs
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2020-04-18 15:10:59 +0200
committerDaniel <kingdread@gmx.de>2020-04-18 15:10:59 +0200
commit7030224fd2a97b3551fdd47c43249e3a42341238 (patch)
treee5986f57f186ab061db9030c5f10285c3eb6b6d7 /src/filters/mod.rs
parent79752779036d31ee6427c731cd7c058eccf1034a (diff)
downloadraidgrep-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.
Diffstat (limited to 'src/filters/mod.rs')
-rw-r--r--src/filters/mod.rs22
1 files changed, 20 insertions, 2 deletions
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::*;