From 5dbea93266c3a30dac5ec6f5a7915d73a440f573 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 25 Apr 2020 13:14:30 +0200 Subject: 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 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). --- src/filters/mod.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/filters/mod.rs') 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: Send + Sync + fmt::Debug { } #[derive(Debug, Clone, Copy)] -pub struct Const(pub bool); - -impl Const { - pub fn new(output: bool) -> Box> { - Box::new(Const(output)) - } -} +struct Const(pub bool); impl Filter for Const { fn filter_early(&self, _: &E) -> Inclusion { @@ -92,6 +85,11 @@ impl Filter for Const { } } +/// Construct a `Filter` that always returns a fixed value. +pub fn constant(output: bool) -> Box> { + Box::new(Const(output)) +} + struct AndFilter(Box>, Box>); impl Filter for AndFilter { -- cgit v1.2.3