diff options
author | Daniel <kingdread@gmx.de> | 2020-04-10 14:25:02 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2020-04-10 14:25:02 +0200 |
commit | 3c429432382dfad6d4ac97349c96e4a4eb292089 (patch) | |
tree | 56ce917134047b890a15cc46e7f430e823106482 /src/output/pipeline.rs | |
parent | de9e9c4d7a0b656b38c17c1a88631ba207419b02 (diff) | |
download | raidgrep-3c429432382dfad6d4ac97349c96e4a4eb292089.tar.gz raidgrep-3c429432382dfad6d4ac97349c96e4a4eb292089.tar.bz2 raidgrep-3c429432382dfad6d4ac97349c96e4a4eb292089.zip |
pipeline: accept boxed trait objects
It's kinda silly to have new() be generic when all it does is box the
objects anyway. It only makes code harder to write, as we cannot unify
the types to call Pipeline::new(), and instead we have to rely on
calling Pipeline::new() in the branches themselves.
It's not the biggest issue when we only have different formats, but at
some point we might want to add different aggregators as well (like a
sorting one or a counting one), so it would be bad if we suddenly had to
add all those branches.
This fix changes that, and we can build the pipeline piecewise by
having a Box<dyn Format> around, allowing us to combine it freely with
any Box<dyn Aggregator>.
Diffstat (limited to 'src/output/pipeline.rs')
-rw-r--r-- | src/output/pipeline.rs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/output/pipeline.rs b/src/output/pipeline.rs index fb23a6f..9664928 100644 --- a/src/output/pipeline.rs +++ b/src/output/pipeline.rs @@ -1,22 +1,24 @@ -use super::{formats::Format, aggregators::Aggregator}; use super::super::LogResult; +use super::{aggregators::Aggregator, formats::Format}; use std::{io::Write, sync::Mutex}; - pub struct Pipeline { format: Box<dyn Format>, aggregator: Box<dyn Aggregator>, writer: Mutex<Box<dyn Write + Send>>, } - impl Pipeline { - pub fn new<W: Write + 'static + Send, F: Format + 'static, A: Aggregator + 'static>(writer: W, format: F, aggregator: A) -> Pipeline { + pub fn new( + writer: Box<dyn Write + Send>, + format: Box<dyn Format>, + aggregator: Box<dyn Aggregator>, + ) -> Pipeline { Pipeline { - format: Box::new(format), - aggregator: Box::new(aggregator), - writer: Mutex::new(Box::new(writer)), + format, + aggregator, + writer: Mutex::new(writer), } } |