aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel <kingdread@gmx.de>2020-04-04 14:13:59 +0200
committerDaniel <kingdread@gmx.de>2020-04-04 14:13:59 +0200
commitc748642f3b801aa5ff4044ab60b0d0c29037a802 (patch)
treeabfd9f5d4cb6f4f4024673ca99716c8ab1d510a4 /src
parent5d2f51ab8593946a0f24db367a887a37258901d5 (diff)
downloadraidgrep-c748642f3b801aa5ff4044ab60b0d0c29037a802.tar.gz
raidgrep-c748642f3b801aa5ff4044ab60b0d0c29037a802.tar.bz2
raidgrep-c748642f3b801aa5ff4044ab60b0d0c29037a802.zip
make pipeline working
Diffstat (limited to 'src')
-rw-r--r--src/output/aggregators.rs12
-rw-r--r--src/output/formats.rs7
-rw-r--r--src/output/mod.rs14
-rw-r--r--src/output/pipeline.rs6
4 files changed, 14 insertions, 25 deletions
diff --git a/src/output/aggregators.rs b/src/output/aggregators.rs
index 9934fb3..5d0429c 100644
--- a/src/output/aggregators.rs
+++ b/src/output/aggregators.rs
@@ -8,11 +8,11 @@
//! an Aggregator must make sure that the data is protected by a mutex or similar.
use super::{super::LogResult, formats::Format};
-use std::{io::Write, sync::Mutex};
+use std::io::Write;
pub trait Aggregator: Sync {
- fn push_item(&self, item: &LogResult, format: &Format, stream: &mut Write);
- fn finish(self, format: &Format, stream: &mut Write);
+ fn push_item(&self, item: &LogResult, format: &dyn Format, stream: &mut dyn Write);
+ fn finish(self, format: &dyn Format, stream: &mut dyn Write);
}
@@ -22,11 +22,11 @@ pub struct WriteThrough;
impl Aggregator for WriteThrough {
- fn push_item(&self, item: &LogResult, format: &Format, stream: &mut Write) {
+ fn push_item(&self, item: &LogResult, format: &dyn Format, stream: &mut dyn Write) {
let text = format.format_result(item);
- println!("Aggregator::push_item {:?}", text);
stream.write_all(text.as_bytes()).unwrap();
+ stream.flush().unwrap();
}
- fn finish(self, format: &Format, stream: &mut Write) {}
+ fn finish(self, _: &dyn Format, _: &mut dyn Write) {}
}
diff --git a/src/output/formats.rs b/src/output/formats.rs
index fe6e982..a5171a8 100644
--- a/src/output/formats.rs
+++ b/src/output/formats.rs
@@ -10,13 +10,6 @@ pub trait Format: Sync + Send {
}
-impl<T: Format + ?Sized> Format for Box<T> {
- fn format_result(&self, item: &LogResult) -> String {
- (&*self).format_result(item)
- }
-}
-
-
/// The human readable, colored format.
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct HumanReadable;
diff --git a/src/output/mod.rs b/src/output/mod.rs
index dfb3ea8..73af5ab 100644
--- a/src/output/mod.rs
+++ b/src/output/mod.rs
@@ -1,4 +1,3 @@
-use super::errors::RuntimeError;
use super::{FightOutcome, LogResult, Opt};
use std::io;
@@ -7,20 +6,17 @@ pub mod formats;
pub mod aggregators;
pub mod pipeline;
-use self::formats::Format;
-use self::aggregators::Aggregator;
pub use self::pipeline::Pipeline;
/// Build an pipeline for the given command line options.
pub fn build_pipeline(opt: &Opt) -> Pipeline {
let stream = io::stdout();
+ let aggregator = aggregators::WriteThrough;
- let formatter: Box<dyn Format> = if opt.file_name_only {
- Box::new(formats::FileOnly)
+ if opt.file_name_only {
+ Pipeline::new(stream, formats::FileOnly, aggregator)
} else {
- Box::new(formats::HumanReadable)
- };
-
- Pipeline::new(stream, formatter, aggregators::WriteThrough)
+ Pipeline::new(stream, formats::HumanReadable, aggregator)
+ }
}
diff --git a/src/output/pipeline.rs b/src/output/pipeline.rs
index 9b3c7e5..fb23a6f 100644
--- a/src/output/pipeline.rs
+++ b/src/output/pipeline.rs
@@ -7,12 +7,12 @@ use std::{io::Write, sync::Mutex};
pub struct Pipeline {
format: Box<dyn Format>,
aggregator: Box<dyn Aggregator>,
- writer: Mutex<Box<dyn Write>>,
+ writer: Mutex<Box<dyn Write + Send>>,
}
impl Pipeline {
- pub fn new<W: Write + 'static, F: Format + 'static, A: Aggregator + 'static>(writer: W, format: F, aggregator: A) -> Pipeline {
+ pub fn new<W: Write + 'static + Send, F: Format + 'static, A: Aggregator + 'static>(writer: W, format: F, aggregator: A) -> Pipeline {
Pipeline {
format: Box::new(format),
aggregator: Box::new(aggregator),
@@ -22,6 +22,6 @@ impl Pipeline {
pub fn push_item(&self, item: &LogResult) {
let mut writer = self.writer.lock().unwrap();
- self.aggregator.push_item(item, &self.format, &mut *writer);
+ self.aggregator.push_item(item, &*self.format, &mut *writer);
}
}