pub trait WriterReporter {
// Required methods
fn write_diff_to<W: Write>(
&self,
result: &DiffResult,
old_sbom: &NormalizedSbom,
new_sbom: &NormalizedSbom,
config: &ReportConfig,
writer: &mut W,
) -> Result<(), ReportError>;
fn write_view_to<W: Write>(
&self,
sbom: &NormalizedSbom,
config: &ReportConfig,
writer: &mut W,
) -> Result<(), ReportError>;
fn format(&self) -> ReportFormat;
}Expand description
Trait for writing reports directly to a Write sink.
Every ReportGenerator automatically implements this trait via a blanket
impl that generates the full report string and writes it. Reporters that
can write incrementally (e.g., StreamingJsonReporter,
NdjsonReporter) override this with truly streaming implementations
that avoid buffering the entire output in memory.
§Example
use sbom_tools::reports::{WriterReporter, JsonReporter, ReportConfig};
use std::io::BufWriter;
use std::fs::File;
let reporter = JsonReporter::new();
let file = File::create("report.json")?;
let mut writer = BufWriter::new(file);
reporter.write_diff_to(&result, &old, &new, &config, &mut writer)?;Required Methods§
Sourcefn write_diff_to<W: Write>(
&self,
result: &DiffResult,
old_sbom: &NormalizedSbom,
new_sbom: &NormalizedSbom,
config: &ReportConfig,
writer: &mut W,
) -> Result<(), ReportError>
fn write_diff_to<W: Write>( &self, result: &DiffResult, old_sbom: &NormalizedSbom, new_sbom: &NormalizedSbom, config: &ReportConfig, writer: &mut W, ) -> Result<(), ReportError>
Write a diff report to a writer.
Implementations may buffer the full report or write incrementally depending on the reporter type.
Sourcefn write_view_to<W: Write>(
&self,
sbom: &NormalizedSbom,
config: &ReportConfig,
writer: &mut W,
) -> Result<(), ReportError>
fn write_view_to<W: Write>( &self, sbom: &NormalizedSbom, config: &ReportConfig, writer: &mut W, ) -> Result<(), ReportError>
Write a view report to a writer.
Sourcefn format(&self) -> ReportFormat
fn format(&self) -> ReportFormat
Get the format this reporter produces
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl WriterReporter for NdjsonReporter
impl WriterReporter for StreamingJsonReporter
impl<T: ReportGenerator> WriterReporter for T
Blanket implementation of WriterReporter for any ReportGenerator.
Generates the full report in memory, then writes it. This is not
streaming — it buffers the entire output. Reporters that need true
incremental output (e.g., for very large SBOMs) should implement
WriterReporter directly.