14 releases (7 breaking)

0.8.1 Jul 18, 2022
0.7.2 Jun 26, 2022
0.7.0 Sep 26, 2021
0.6.0 Jul 28, 2020
0.4.0 Feb 18, 2018

#461 in Parser implementations

Download history 121/week @ 2024-02-26 278/week @ 2024-03-04 117/week @ 2024-03-11 173/week @ 2024-03-18 152/week @ 2024-03-25 284/week @ 2024-04-01 409/week @ 2024-04-08 155/week @ 2024-04-15 366/week @ 2024-04-22 476/week @ 2024-04-29 607/week @ 2024-05-06 524/week @ 2024-05-13 196/week @ 2024-05-20 320/week @ 2024-05-27 866/week @ 2024-06-03 1094/week @ 2024-06-10

2,620 downloads per month
Used in 5 crates


1.5K SLoC


maintenance status: passively-maintained license crates.io docs.rs rust 1.56.1+ badge Rust CI codecov

LCOV tracefile parser/merger/filter in pure Rust.

LCOV is a graphical front-end for coverage testing tool gcov. It collects gcov data for multiple source files and stores them into the file called as "tracefile".

The purpose of this crate is to operate the LCOV tracefile faster than the original LCOV Perl implementation.


Add this to your Cargo.toml:

lcov = "0.8.1"


See the README of lcov-util.

Data structure

In this crate, the data structure corresponding to each line of the LCOV tracefile is called "LCOV record" and is represented as Record. Each line of the LCOV tracefile is composed of a string representing a kind of the record, a colon, a comma-separated field list:


LCOV record kind is represented as a variant of Record or RecordKind. Each fields of an LCOV record are represented as fields of a struct-like variant of Record.

For details of the LCOV tracefile syntax, see the manpage of geninfo.


Parsing an LCOV tracefile:

use lcov::{Record, RecordKind, Reader};

// `Reader` is an iterator that iterates over `Result<lcov::Record, E>` read from the input buffer.
let mut reader = Reader::open_file("tests/fixtures/report.info")?;

// Collect the read records into a vector.
let records = reader.collect::<Result<Vec<_>, _>>()?;
assert_eq!(records[0], Record::TestName { name: "".into() });
assert_eq!(records[1].kind(), RecordKind::SourceFile);

// Outputs the read records in LCOV tracefile format.
for record in records {
    println!("{}", record);

Creating an LCOV report from String:

use lcov::{Reader, Record};

let input = "\

// `&[u8]` implements `BufRead`, so you can pass it as an argument to `Reader::new`.
let mut reader = Reader::new(input.as_bytes());

let records = reader.collect::<Result<Vec<_>, _>>()?;
assert_eq!(records[0], Record::TestName { name: "test_name".into() });
assert_eq!(records[1], Record::SourceFile { path: "/path/to/source/file.rs".into() });

// Creates an `String` in tracefile format. In this example, it is the same as `input`.
let output = records.into_iter().map(|rec| format!("{}\n", rec)).collect::<String>();
assert_eq!(input, output);

Merging tracefiles:

use lcov::{Record, RecordKind, Report};

// Creates an empty `Report`.
let mut report = Report::new();

// Merges a first file.

// Merges a second file.

// Outputs the merge result in LCOV tracefile format.
for record in report.into_records() {
    println!("{}", record);

Minimum supported Rust version (MSRV)

The minimum supported Rust version is Rust 1.56.1. At least the last 3 versions of stable Rust are supported at any given time.

While a crate is pre-release status (0.x.x) it may have its MSRV bumped in a patch release. Once a crate has reached 1.x, any MSRV bump will be accompanied with a new minor version.


This project is licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in lcov by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~18K SLoC