json.rs
This file
Path
src/export/json.rs
33 lines · 731 bytes · Rust
Last changed by
Add new --sort optionDavid Peterbefore adoptionac617c8
History of this fileTake it
1use serde::*;2use serde_json::to_vec_pretty;34use super::Exporter;5use crate::benchmark::benchmark_result::BenchmarkResult;6use crate::options::SortOrder;7use crate::util::units::Unit;89use anyhow::Result;1011#[derive(Serialize, Debug)]12struct HyperfineSummary<'a> {13 results: &'a [BenchmarkResult],14}1516#[derive(Default)]17pub struct JsonExporter {}1819impl Exporter for JsonExporter {20 fn serialize(21 &self,22 results: &[BenchmarkResult],23 _unit: Option<Unit>,24 _sort_order: SortOrder,25 ) -> Result<Vec<u8>> {26 let mut output = to_vec_pretty(&HyperfineSummary { results });27 if let Ok(ref mut content) = output {28 content.push(b'\n');29 }3031 Ok(output?)32 }33}