Skip to main content

executable_stories/
json_writer.rs

1use std::fs;
2use std::path::Path;
3
4use crate::types::RawRun;
5
6/// Write a `RawRun` to disk as pretty-printed JSON.
7///
8/// Creates parent directories if they don't already exist.
9///
10/// # Errors
11///
12/// Returns an error if directory creation or file write fails.
13pub fn write_raw_run(run: &RawRun, output_path: &str) -> std::io::Result<()> {
14    if let Some(parent) = Path::new(output_path).parent() {
15        fs::create_dir_all(parent)?;
16    }
17    let json = serde_json::to_string_pretty(run)?;
18    fs::write(output_path, json)?;
19    Ok(())
20}