Skip to content
Myr

Use skip_serializing_if

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

authored by sharkdp · committed by David Peter · parent 8a25885 · Browse files · 2 files+8 added−26 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−26 removed

  • other:+8 added−26 removed

2 files+8 added−26 removed

modified:src/hyperfine/export/csv.rs+5 added-24 removed
2 unmodified lines
3use std::io::{Error, ErrorKind, Result};45use csv::WriterBuilder;67use hyperfine::internal::Second;89/// Set of values that will be exported.10#[derive(Debug, Serialize)]11pub struct CsvEntry {12 command: String,13 mean: Second,14 stddev: Second,15 user: Second,16 system: Second,17 min: Second,18 max: Second,19}20217#[derive(Default)]8pub struct CsvExporter {}910impl Exporter for CsvExporter {11 fn serialize(&self, results: &Vec<ExportEntry>) -> Result<Vec<u8>> {12 let mut writer = WriterBuilder::new().from_writer(vec![]);13 for res in results {29 writer.serialize(&CsvEntry {30 command: res.command.clone(),31 mean: res.mean,32 stddev: res.stddev,33 user: res.user,34 system: res.system,35 min: res.min,36 max: res.max,37 })?;14 // The list of times can not be exported to the CSV file - remove it:15 let mut result = res.clone();16 result.times = None;1718 writer.serialize(result)?;19 }2021 writer22 .into_inner()
3 unmodified lines
modified:src/hyperfine/export/mod.rs+3 added-2 removed
34 unmodified lines
35 /// Max time measured36 max: Second,3738 /// All run time measurements39 times: Vec<Second>,39 #[serde(skip_serializing_if = "Option::is_none")]40 times: Option<Vec<Second>>,41}4243impl ExportEntry {44 /// Create a new entry with the given values.
14 unmodified lines
59 user,60 system,61 min,62 max,62 times,63 times: Some(times),64 }65 }66}67
65 unmodified lines