Skip to content
Myr

json.rs

This file

Path

src/export/json.rs

27 lines · 634 bytes · Rust

Last changed by

Move functionality to schedulerDavid Peterbefore adoptiondcfeede

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::util::units::Unit;78use anyhow::Result;910#[derive(Serialize, Debug)]11struct HyperfineSummary<'a> {12    results: &'a [BenchmarkResult],13}1415#[derive(Default)]16pub struct JsonExporter {}1718impl Exporter for JsonExporter {19    fn serialize(&self, results: &[BenchmarkResult], _unit: Option<Unit>) -> Result<Vec<u8>> {20        let mut output = to_vec_pretty(&HyperfineSummary { results });21        for content in output.iter_mut() {22            content.push(b'\n');23        }2425        Ok(output?)26    }27}