sarif_rust 0.3.0

A comprehensive Rust library for parsing, generating, and manipulating SARIF (Static Analysis Results Interchange Format) v2.1.0 files
Documentation
//! SARIF parsing and serialization functionality
//!
//! This module provides functions for parsing SARIF files from various sources
//! and serializing SARIF objects back to JSON.

pub use error::*;
pub use json_parser::*;
pub use validator::*;

pub mod error;
pub mod json_parser;
pub mod validator;

// Re-export common parsing functions
use crate::types::SarifLog;
use std::fs::File;
use std::io::{BufReader, BufWriter, Write};
use std::path::Path;

/// Parse SARIF from a file path
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<SarifLog, crate::parser::SarifError> {
    let file = File::open(path)?;
    let reader = BufReader::new(file);
    let sarif: SarifLog = serde_json::from_reader(reader)?;
    Ok(sarif)
}

/// Parse SARIF from a JSON string
pub fn from_str(json: &str) -> Result<SarifLog, crate::parser::SarifError> {
    let sarif: SarifLog = serde_json::from_str(json)?;
    Ok(sarif)
}

/// Serialize SARIF to JSON string
pub fn to_string(sarif: &SarifLog) -> Result<String, crate::parser::SarifError> {
    let json = serde_json::to_string(sarif)?;
    Ok(json)
}

/// Serialize SARIF to pretty-printed JSON string  
pub fn to_string_pretty(sarif: &SarifLog) -> Result<String, crate::parser::SarifError> {
    let json = serde_json::to_string_pretty(sarif)?;
    Ok(json)
}

/// Write SARIF to a file
pub fn to_file<P: AsRef<Path>>(sarif: &SarifLog, path: P) -> Result<(), crate::parser::SarifError> {
    let file = File::create(path)?;
    let mut writer = BufWriter::new(file);
    serde_json::to_writer_pretty(&mut writer, sarif)?;
    writer.flush()?;
    Ok(())
}