aboutsummaryrefslogtreecommitdiff
path: root/src/filters/mod.rs
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2020-04-25 13:14:30 +0200
committerDaniel <kingdread@gmx.de>2020-04-25 13:19:42 +0200
commit5dbea93266c3a30dac5ec6f5a7915d73a440f573 (patch)
tree9b7bba1b25b2ccebd0b5ed705bf8b7238ddb0893 /src/filters/mod.rs
parent509e5817e6e035e762840c00fb95b18253b1d269 (diff)
downloadraidgrep-5dbea93266c3a30dac5ec6f5a7915d73a440f573.tar.gz
raidgrep-5dbea93266c3a30dac5ec6f5a7915d73a440f573.tar.bz2
raidgrep-5dbea93266c3a30dac5ec6f5a7915d73a440f573.zip
use free functions instead of Filter::new
Having a ::new on each of the filter types was a bit weird, especially because we returned Box<dyn ...> instead of Self (and clippy rightfully complained). With this patch, we now have a bunch of normal functions, and we don't show to the outside how a filter is actually implemented (or what struct is behind it).
Diffstat (limited to 'src/filters/mod.rs')
-rw-r--r--src/filters/mod.rs14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/filters/mod.rs b/src/filters/mod.rs
index 3d0868b..162b6f8 100644
--- a/src/filters/mod.rs
+++ b/src/filters/mod.rs
@@ -1,4 +1,3 @@
-#![allow(clippy::new_ret_no_self)]
use std::{fmt, ops};
use num_derive::FromPrimitive;
@@ -74,13 +73,7 @@ pub trait Filter<Early, Late>: Send + Sync + fmt::Debug {
}
#[derive(Debug, Clone, Copy)]
-pub struct Const(pub bool);
-
-impl Const {
- pub fn new<E, L>(output: bool) -> Box<dyn Filter<E, L>> {
- Box::new(Const(output))
- }
-}
+struct Const(pub bool);
impl<E, L> Filter<E, L> for Const {
fn filter_early(&self, _: &E) -> Inclusion {
@@ -92,6 +85,11 @@ impl<E, L> Filter<E, L> for Const {
}
}
+/// Construct a `Filter` that always returns a fixed value.
+pub fn constant<E, L>(output: bool) -> Box<dyn Filter<E, L>> {
+ Box::new(Const(output))
+}
+
struct AndFilter<E, L>(Box<dyn Filter<E, L>>, Box<dyn Filter<E, L>>);
impl<E, L> Filter<E, L> for AndFilter<E, L> {