Skip to main content

CoveragePort

Trait CoveragePort 

Source
pub trait CoveragePort {
    type Diagnostic: ParseDiagnostic;

    // Required method
    fn parse(
        &self,
        path: &Path,
    ) -> Result<ParseOutput<Self::Diagnostic>, CrapError>;

    // Provided method
    fn validate(&self, _path: &Path) -> Result<(), String> { ... }
}
Expand description

Port for parsing coverage data into per-file, per-line hit counts.

Diagnostic associated type lets concrete impls fix their parse diagnostic shape (LcovParseDiagnostic for the Rust adapter). The trait is dyn-compatible when callers fix the associated type at the dyn site: &dyn CoveragePort<Diagnostic = LcovParseDiagnostic>. See ADR D9 for the mixed-dispatch rationale.

Required Associated Types§

Required Methods§

Source

fn parse(&self, path: &Path) -> Result<ParseOutput<Self::Diagnostic>, CrapError>

Parse the coverage file at path into per-file line / branch hit data.

Takes &Path (not &str) so each impl owns its read strategy: LCOV stays free to stream line-by-line via BufReader, Istanbul JSON slurps once and hands the buffer to serde_json. Forcing the caller to pre-read into a String would (a) require slurp universally even when streaming is viable and (b) double peak RSS on every invocation since Self::validate already takes &Path and may stream the same file. Per the feedback_trait_io_input_path_over_str operational rule, port methods that gate on file content take &Path.

Provided Methods§

Source

fn validate(&self, _path: &Path) -> Result<(), String>

Adapter-aware pre-flight check: does the file at path contain at least one usable coverage record? Runs before the analyzer dispatches to parse, so the CLI can surface a helpful “your coverage file has no data points” diagnostic before the full parse pass.

Takes &Path (not &str) so adapters can stream the file line-by-line and short-circuit on the first valid record — the LCOV format easily exceeds 100 MB on large workspaces and loading the whole file into memory twice (once here, once in parse) would double peak RSS for no semantic gain. Adapters that need random access (Istanbul JSON) can still slurp via read_to_string internally.

Default implementation returns Ok(()) (skip validation) — adapters with a cheap structural signature override. The LCOV adapter checks for SF: + DA: records; the Istanbul adapter checks for at least one entry with a non-empty statementMap.

The returned Err(String) is the structural reason (e.g., "no SF/DA records"); the CLI layer pairs it with the coverage path and adapter-specific generation hint (AdapterMeta::coverage_hint) before surfacing to the user.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§