diff options
author | Daniel <kingdread@gmx.de> | 2019-06-03 02:02:44 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2019-06-03 02:02:44 +0200 |
commit | 5d2f51ab8593946a0f24db367a887a37258901d5 (patch) | |
tree | 498f2af9584046ed63f256375169bbf5756bfb7d /src/output/pipeline.rs | |
parent | c731b470fc162e56f6d81c475bacb41230a5e2d3 (diff) | |
download | raidgrep-5d2f51ab8593946a0f24db367a887a37258901d5.tar.gz raidgrep-5d2f51ab8593946a0f24db367a887a37258901d5.tar.bz2 raidgrep-5d2f51ab8593946a0f24db367a887a37258901d5.zip |
[WIP] rewrite output logic as a pipeline
Diffstat (limited to 'src/output/pipeline.rs')
-rw-r--r-- | src/output/pipeline.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/output/pipeline.rs b/src/output/pipeline.rs new file mode 100644 index 0000000..9b3c7e5 --- /dev/null +++ b/src/output/pipeline.rs @@ -0,0 +1,27 @@ +use super::{formats::Format, aggregators::Aggregator}; +use super::super::LogResult; + +use std::{io::Write, sync::Mutex}; + + +pub struct Pipeline { + format: Box<dyn Format>, + aggregator: Box<dyn Aggregator>, + writer: Mutex<Box<dyn Write>>, +} + + +impl Pipeline { + pub fn new<W: Write + 'static, F: Format + 'static, A: Aggregator + 'static>(writer: W, format: F, aggregator: A) -> Pipeline { + Pipeline { + format: Box::new(format), + aggregator: Box::new(aggregator), + writer: Mutex::new(Box::new(writer)), + } + } + + pub fn push_item(&self, item: &LogResult) { + let mut writer = self.writer.lock().unwrap(); + self.aggregator.push_item(item, &self.format, &mut *writer); + } +} |