Skip to main content

WriterReporter

Trait WriterReporter 

Source
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§

Source

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.

Source

fn write_view_to<W: Write>( &self, sbom: &NormalizedSbom, config: &ReportConfig, writer: &mut W, ) -> Result<(), ReportError>

Write a view report to a writer.

Source

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§

Source§

impl WriterReporter for NdjsonReporter

Source§

impl WriterReporter for StreamingJsonReporter

Source§

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.