forge-guard 0.1.4

Pre-deployment smart contract auditing framework for Foundry
Documentation
//! JSON report generation.

use super::ReportGenerator;
use crate::core::{AuditResult, ForgeGuardError};
use std::path::Path;

/// JSON report generator.
pub struct JsonReport;

impl ReportGenerator for JsonReport {
    fn generate(&self, result: &AuditResult) -> Result<String, ForgeGuardError> {
        Ok(serde_json::to_string_pretty(result)?)
    }

    fn extension(&self) -> &'static str {
        "json"
    }
}

/// Write audit result as JSON to a file.
pub fn write_report(result: &AuditResult, path: &Path) -> Result<(), ForgeGuardError> {
    let json = serde_json::to_string_pretty(result)?;
    std::fs::write(path, json)?;
    Ok(())
}