Skip to content
Myr

json.rs

This file

Path

src/export/json.rs

33 lines · 736 bytes · Rust

Last changed by

Merge pull request #962 from sharkdp/codex/quantity-module-layoutDavid Peterbefore adoptionecf8a24

History of this file

Take it

1use serde::*;2use serde_json::to_vec_pretty;34use super::Exporter;5use crate::benchmark::benchmark_result::BenchmarkResult;6use crate::options::SortOrder;7use crate::quantity::TimeUnit;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<TimeUnit>,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}