sarif_rust/lib.rs
1//! # SARIF Rust Library
2//!
3//! A comprehensive Rust library for parsing, generating, and manipulating
4//! SARIF (Static Analysis Results Interchange Format) v2.1.0 files.
5//!
6//! SARIF is a standard JSON format for the output of static analysis tools.
7//! This library provides complete support for the SARIF v2.1.0 specification
8//! with type-safe parsing, generation, validation, and manipulation capabilities.
9//!
10//! ## Features
11//!
12//! - **Complete SARIF v2.1.0 Support**: Full specification compliance with all optional fields
13//! - **Type-Safe API**: Leverages Rust's type system for correctness and safety
14//! - **Builder Pattern**: Ergonomic API for programmatic SARIF generation
15//! - **Advanced Querying**: Powerful filtering and search capabilities
16//! - **Merge & Diff**: Combine multiple SARIF files or compare them
17//! - **Multiple Formats**: Export to CSV, HTML, GitHub Security Advisory format
18//! - **High Performance**: Streaming parser for large files with memory efficiency
19//! - **Comprehensive Validation**: Multiple validation levels from minimal to pedantic
20//! - **Schema Evolution**: Automatic migration between SARIF versions
21//!
22//! ## Quick Start
23//!
24//! ### Parsing SARIF Files
25//!
26//! ```rust,no_run
27//! use sarif_rust::SarifLog;
28//!
29//! // Parse from file
30//! let sarif: SarifLog = sarif_rust::from_file("results.sarif")?;
31//!
32//! // Parse from string
33//! let json_content = std::fs::read_to_string("results.sarif")?;
34//! let sarif: SarifLog = sarif_rust::from_str(&json_content)?;
35//!
36//! // Access results
37//! for run in &sarif.runs {
38//!     println!("Tool: {}", run.tool.driver.name);
39//!     if let Some(results) = &run.results {
40//!         for result in results {
41//!             println!("  Issue: {}",
42//!                 result.message.text.as_deref().unwrap_or("no message"));
43//!         }
44//!     }
45//! }
46//! # Ok::<(), Box<dyn std::error::Error>>(())
47//! ```
48//!
49//! ### Building SARIF Files
50//!
51//! ```rust
52//! use sarif_rust::SarifLogBuilder;
53//!
54//! // Create a basic SARIF log
55//! let sarif = SarifLogBuilder::new()
56//!     .with_schema("https://json.schemastore.org/sarif-2.1.0.json")
57//!     .build_unchecked(); // Note: use build()? for validation
58//!
59//! // Convert to JSON
60//! let json = sarif_rust::to_string_pretty(&sarif)?;
61//! println!("{}", json);
62//! # Ok::<(), Box<dyn std::error::Error>>(())
63//! ```
64//!
65//! ## Error Handling
66//!
67//! All operations return `Result<T, SarifError>` where `SarifError` provides
68//! detailed information about what went wrong:
69//!
70//! ```rust,no_run
71//! use sarif_rust::SarifError;
72//!
73//! match sarif_rust::from_file("invalid.sarif") {
74//!     Ok(sarif) => println!("Parsed successfully"),
75//!     Err(SarifError::Io(e)) => eprintln!("IO error: {}", e),
76//!     Err(SarifError::Json(e)) => eprintln!("JSON parsing error: {}", e),
77//!     Err(SarifError::Validation(e)) => eprintln!("Validation error: {}", e),
78//!     Err(e) => eprintln!("Other error: {}", e),
79//! }
80//! # Ok::<(), Box<dyn std::error::Error>>(())
81//! ```
82
83// Re-export core types
84pub use builder::*;
85pub use parser::*;
86pub use types::*;
87
88// Core modules
89pub mod builder;
90pub mod parser;
91pub mod types;
92pub mod utils;
93
94/// Re-export commonly used types and functions for convenience
95pub mod prelude {
96    pub use crate::builder::*;
97    pub use crate::parser::{
98        SarifParser, SarifValidator, parse_sarif_from_str, serialize_sarif_to_string,
99    };
100    pub use crate::types::*;
101}
102
103// Re-export common functions
104pub use parser::{from_file, from_str, to_string, to_string_pretty, to_file};
105
106/// Library version
107pub const VERSION: &str = env!("CARGO_PKG_VERSION");
108
109/// SARIF specification version supported
110pub const SARIF_VERSION: &str = "2.1.0";