modify types for serialization and deserialization

The existing types need to be modified so they can be used for the
deserialization process.
This commit is contained in:
Richard Montoya 2023-07-26 23:09:41 -05:00
parent 6746cf120d
commit b90fa23237
2 changed files with 8 additions and 8 deletions

View File

@ -1,20 +1,20 @@
use std::collections::BTreeMap;
use serde::Serialize;
use serde::{Serialize, Deserialize};
use crate::util::units::Second;
/// Set of values that will be exported.
// NOTE: `serde` is used for JSON serialization, but not for CSV serialization due to the
// `parameters` map. Update `src/hyperfine/export/csv.rs` with new fields, as appropriate.
#[derive(Debug, Default, Clone, Serialize, PartialEq)]
#[derive(Debug, Default, Clone, Serialize, Deserialize ,PartialEq)]
pub struct BenchmarkResult {
/// The full command line of the program that is being benchmarked
pub command: String,
/// The full command line of the program that is being benchmarked, possibly including a list of
/// parameters that were not used in the command line template.
#[serde(skip_serializing)]
#[serde(skip)]
pub command_with_unused_parameters: String,
/// The average run time
@ -46,6 +46,6 @@ pub struct BenchmarkResult {
pub exit_codes: Vec<Option<i32>>,
/// Parameter values for this benchmark
#[serde(skip_serializing_if = "BTreeMap::is_empty")]
#[serde(default, skip_serializing_if = "BTreeMap::is_empty")]
pub parameters: BTreeMap<String, String>,
}

View File

@ -8,9 +8,9 @@ use crate::util::units::Unit;
use anyhow::Result;
#[derive(Serialize, Debug)]
struct HyperfineSummary<'a> {
results: &'a [BenchmarkResult],
#[derive(Serialize, Deserialize, Debug)]
pub struct HyperfineSummary {
results: Vec<BenchmarkResult>,
}
#[derive(Default)]
@ -23,7 +23,7 @@ impl Exporter for JsonExporter {
_unit: Option<Unit>,
_sort_order: SortOrder,
) -> Result<Vec<u8>> {
let mut output = to_vec_pretty(&HyperfineSummary { results });
let mut output = to_vec_pretty(&HyperfineSummary { results: results.to_vec() });
if let Ok(ref mut content) = output {
content.push(b'\n');
}