Skip to main content

powerio_matrix/io/
meta.rs

1//! Per case metadata: matrices emitted, their stats, source file digest,
2//! build options. Used by the TUI Inspect screen and as a sidecar for
3//! downstream tooling.
4
5use std::path::Path;
6
7use serde::{Deserialize, Serialize};
8
9use crate::Result;
10use crate::matrix::{BuildOptions, MatrixStats};
11
12#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct CaseMetadata {
14    pub case_name: String,
15    pub source_file: Option<String>,
16    pub source_sha256: Option<String>,
17    pub base_mva: f64,
18    pub n_buses: usize,
19    pub n_branches: usize,
20    pub build_options: BuildOptions,
21    pub matrices: Vec<MatrixMetadata>,
22    pub powerio_version: String,
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct MatrixMetadata {
27    pub kind: String,
28    pub file: String,
29    pub stats: MatrixStats,
30    pub sddm: bool,
31}
32
33pub fn write_meta_json(meta: &CaseMetadata, path: impl AsRef<Path>) -> Result<()> {
34    let json = serde_json::to_string_pretty(meta).map_err(|e| crate::Error::Mtx(e.to_string()))?;
35    std::fs::write(path, json)?;
36    Ok(())
37}