Use skip_serializing_if

This commit is contained in:
sharkdp authored and David Peter committed 2018-03-21 07:59:09 +01:00
1 parent 8a25885714
commit 0756558d53
2 files changed
+8 -26

No files matched your search

+5 -24
View File
@@ -4,21 +4,6 @@ use std::io::{Error, ErrorKind, Result};
use csv::WriterBuilder;
use hyperfine::internal::Second;
/// Set of values that will be exported.
#[derive(Debug, Serialize)]
pub struct CsvEntry {
command: String,
mean: Second,
stddev: Second,
user: Second,
system: Second,
min: Second,
max: Second,
}
#[derive(Default)]
pub struct CsvExporter {}
@@ -26,15 +11,11 @@ impl Exporter for CsvExporter {
fn serialize(&self, results: &Vec<ExportEntry>) -> Result<Vec<u8>> {
let mut writer = WriterBuilder::new().from_writer(vec![]);
for res in results {
writer.serialize(&CsvEntry {
command: res.command.clone(),
mean: res.mean,
stddev: res.stddev,
user: res.user,
system: res.system,
min: res.min,
max: res.max,
})?;
// The list of times can not be exported to the CSV file - remove it:
let mut result = res.clone();
result.times = None;
writer.serialize(result)?;
}
writer
+3 -2
View File
@@ -36,7 +36,8 @@ pub struct ExportEntry {
max: Second,
/// All run time measurements
times: Vec<Second>,
#[serde(skip_serializing_if = "Option::is_none")]
times: Option<Vec<Second>>,
}
impl ExportEntry {
@@ -59,7 +60,7 @@ impl ExportEntry {
system,
min,
max,
times,
times: Some(times),
}
}
}