pub use error::*;
pub use json_parser::*;
pub use validator::*;
pub mod error;
pub mod json_parser;
pub mod validator;
use crate::types::SarifLog;
use std::fs::File;
use std::io::{BufReader, BufWriter, Write};
use std::path::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)
}
pub fn from_str(json: &str) -> Result<SarifLog, crate::parser::SarifError> {
let sarif: SarifLog = serde_json::from_str(json)?;
Ok(sarif)
}
pub fn to_string(sarif: &SarifLog) -> Result<String, crate::parser::SarifError> {
let json = serde_json::to_string(sarif)?;
Ok(json)
}
pub fn to_string_pretty(sarif: &SarifLog) -> Result<String, crate::parser::SarifError> {
let json = serde_json::to_string_pretty(sarif)?;
Ok(json)
}
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(())
}