From 3c429432382dfad6d4ac97349c96e4a4eb292089 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 10 Apr 2020 14:25:02 +0200 Subject: 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 around, allowing us to combine it freely with any Box. --- src/output/mod.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/output/mod.rs') diff --git a/src/output/mod.rs b/src/output/mod.rs index 84ed0a4..aadcbf9 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -8,18 +8,20 @@ pub mod pipeline; pub use self::pipeline::Pipeline; +use self::formats::Format; /// Build an pipeline for the given command line options. pub fn build_pipeline(opt: &Opt) -> Pipeline { let stream = io::stdout(); let aggregator = aggregators::WriteThrough; - if opt.file_name_only { - Pipeline::new(stream, formats::FileOnly, aggregator) + let format: Box = if opt.file_name_only { + Box::new(formats::FileOnly) } else { - let format = formats::HumanReadable { + Box::new(formats::HumanReadable { show_guilds: opt.guilds, - }; - Pipeline::new(stream, format, aggregator) - } + }) + }; + + Pipeline::new(Box::new(stream), format, Box::new(aggregator)) } -- cgit v1.2.3