Skip to main content

write

Function write 

Source
pub fn write(report: &CoverageReport) -> Result<String>
Expand description

Renders report as lcov trace text.

The output is a function of the report alone: files come out in path order and each file’s DA records in line order, so two reports that compare equal write byte-identical text, whatever order their inputs were merged in. Every record ends in a newline — the last end_of_record included, which cargo llvm-cov omits and which makes its files unsafe to join with cat.

Only what the line model holds is written: TN, SF, DA, LF, LH and end_of_record. Function (FN*) and branch (BRDA) records are not part of the model and are dropped. LF/LH count the DA records written, so a file is consistent with itself; llvm-cov writes them from its own summary instead, which counts some lines more than once (#2131).

A file with no executable lines is written as an empty record (LF:0, LH:0), the way parse reads one: leaving it out would make the text read back as a different report, and a consumer that ranks a missing file against an empty one would answer differently.

§Errors

Fails when a path has a line break or leading or trailing whitespace. lcov has no way to carry either — parse trims the SF: value and splits on lines — so the text would read back keyed under a different path.