# lcov-parser
LCOV report parser for Rust.
[](https://travis-ci.org/holyshared/lcov-parser)
[](https://ci.appveyor.com/project/holyshared/lcov-parser/branch/master)
[](https://crates.io/crates/lcov-parser)
[](https://github.com/holyshared/lcov-parser/blob/master/LICENSE)
## Basic usage
Create a LCOVParser object, and then parse the data.
```rust
extern crate lcov_parser;
use lcov_parser:: { LCOVParser, LCOVRecord };
fn main() {
let content = concat!(
"TN:test_name\n",
"SF:/path/to/source.rs\n",
"DA:1,2\n",
"DA:2,1\n",
"DA:3,5\n",
"end_of_record\n"
);
let records = LCOVParser::new(content.as_bytes()).parse().unwrap();
for record in records.into_iter() {
match record {
LCOVRecord::TestName(name) => println!("Test: {}", name),
LCOVRecord::SourceFile(file_name) => println!("File: {}", file_name),
LCOVRecord::Data(line_number, execution_count, _) => println!("Line: {}, Executed: {}", line_number, execution_count),
LCOVRecord::EndOfRecord => println!("Finish"),
_ => { continue; }
}
}
}
```
## Parsing the file
It can also be used to parse the report file.
```rust
let mut parser = LCOVParser::from_file("/path/to/report.lcov").unwrap();
let records = parser.parse().unwrap();
for record in records.iter() {
match record {
&LCOVRecord::SourceFile(ref name) => println!("start file: {}", name),
&LCOVRecord::EndOfRecord => println!("end file"),
_ => { continue; }
}
}
```
### Parse of each record
If you want to parse one record at a time, you can use the next method.
```rust
use std::fs:: { File };
use lcov_parser:: { LCOVParser, FromFile };
let mut records = vec![];
let mut parser = LCOVParser::from_file("/path/to/file");
loop {
let result = parser.next().unwrap();
if result.is_none() {
break;
}
let record = result.unwrap();
records.push(record)
}
println!("{:?}", records);
println!("{:?}", records.len());
```
## License
Licensed under either of
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.