diff --git a/src/hyperfine/export/csv.rs b/src/hyperfine/export/csv.rs index bea110e..635d2cd 100644 --- a/src/hyperfine/export/csv.rs +++ b/src/hyperfine/export/csv.rs @@ -4,18 +4,13 @@ use csv::WriterBuilder; use std::io::Result; pub struct CsvExporter { - results: Vec, out_file: String, } impl ResultExporter for CsvExporter { - fn add_entry(&mut self, entry: ExportEntry) { - self.results.push(entry); - } - - fn write(&self) -> Result<()> { + fn write(&self, results: &Vec) -> Result<()> { let mut writer = WriterBuilder::new().from_path(&self.out_file)?; - for res in &self.results { + for res in results { writer.serialize(res)?; } Ok(()) @@ -25,7 +20,6 @@ impl ResultExporter for CsvExporter { impl CsvExporter { pub fn new(file_name: String) -> Self { CsvExporter { - results: Vec::new(), out_file: file_name, } } diff --git a/src/hyperfine/export/mod.rs b/src/hyperfine/export/mod.rs index 0a520ed..716054c 100644 --- a/src/hyperfine/export/mod.rs +++ b/src/hyperfine/export/mod.rs @@ -42,11 +42,9 @@ pub enum ResultExportType { /// A ResultExporter is responsible for writing all results to the /// appropriate file -pub trait ResultExporter { - /// Add an additional entry to the exporter for writing - fn add_entry(&mut self, entry: ExportEntry); +trait ResultExporter { /// Write all entries to the target destination - fn write(&self) -> Result<()>; + fn write(&self, values: &Vec) -> Result<()>; } /// The ExportManager handles coordination of multiple ResultExporters @@ -65,12 +63,14 @@ pub trait ExportManager { pub fn create_export_manager() -> Box { Box::new(Exporter { exporters: Vec::new(), + results: Vec::new(), }) } /// The Exporter is the internal implementation of the ExportManager struct Exporter { exporters: Vec>, + results: Vec, } impl ExportManager for Exporter { @@ -82,14 +82,12 @@ impl ExportManager for Exporter { } fn add_result(&mut self, result: ExportEntry) { - for exp in self.exporters.iter_mut() { - exp.add_entry(result.clone()); - } + self.results.push(result); } fn write_results(&self) -> Result<()> { for exp in &self.exporters { - exp.write()?; + exp.write(&self.results)?; } Ok(()) }