From 5d2f51ab8593946a0f24db367a887a37258901d5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 3 Jun 2019 02:02:44 +0200 Subject: [WIP] rewrite output logic as a pipeline --- src/output/pipeline.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/output/pipeline.rs (limited to 'src/output/pipeline.rs') 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, + aggregator: Box, + writer: Mutex>, +} + + +impl Pipeline { + pub fn new(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); + } +} -- cgit v1.2.3