Skip to content
Myr

Do not copy export items between exporters, write from central vec

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Steve Pentland · committed by David Peter · parent 12d8fdb · Browse files · 2 files+8 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+8 added−16 removed

  • other:+8 added−16 removed

2 files+8 added−16 removed

modified:src/hyperfine/export/csv.rs+2 added-8 removed
2 unmodified lines
3use csv::WriterBuilder;4use std::io::Result;56pub struct CsvExporter {7 results: Vec<ExportEntry>,7 out_file: String,8}910impl ResultExporter for CsvExporter {12 fn add_entry(&mut self, entry: ExportEntry) {13 self.results.push(entry);14 }1516 fn write(&self) -> Result<()> {11 fn write(&self, results: &Vec<ExportEntry>) -> Result<()> {12 let mut writer = WriterBuilder::new().from_path(&self.out_file)?;18 for res in &self.results {13 for res in results {14 writer.serialize(res)?;15 }16 Ok(())17 }
1 unmodified line
1920impl CsvExporter {21 pub fn new(file_name: String) -> Self {22 CsvExporter {28 results: Vec::new(),23 out_file: file_name,24 }25 }26}
modified:src/hyperfine/export/mod.rs+6 added-8 removed
40 unmodified lines
41}4243/// A ResultExporter is responsible for writing all results to the44/// appropriate file45pub trait ResultExporter {46 /// Add an additional entry to the exporter for writing47 fn add_entry(&mut self, entry: ExportEntry);45trait ResultExporter {46 /// Write all entries to the target destination49 fn write(&self) -> Result<()>;47 fn write(&self, values: &Vec<ExportEntry>) -> Result<()>;48}4950/// The ExportManager handles coordination of multiple ResultExporters51pub trait ExportManager {
10 unmodified lines
62/// Create a new ExportManager63pub fn create_export_manager() -> Box<ExportManager> {64 Box::new(Exporter {65 exporters: Vec::new(),66 results: Vec::new(),67 })68}6970/// The Exporter is the internal implementation of the ExportManager71struct Exporter {72 exporters: Vec<Box<ResultExporter>>,73 results: Vec<ExportEntry>,74}7576impl ExportManager for Exporter {77 fn add_exporter(&mut self, for_type: &ResultExportType) {
3 unmodified lines
81 };82 }8384 fn add_result(&mut self, result: ExportEntry) {85 for exp in self.exporters.iter_mut() {86 exp.add_entry(result.clone());87 }85 self.results.push(result);86 }8788 fn write_results(&self) -> Result<()> {89 for exp in &self.exporters {92 exp.write()?;90 exp.write(&self.results)?;91 }92 Ok(())93 }94}