llvm_cov_json/types/
mod.rs

1
2use serde::Deserialize;
3
4mod region;
5pub use region::*;
6
7mod branch;
8pub use branch::*;
9
10mod expansion;
11pub use expansion::*;
12
13mod function;
14pub use function::*;
15
16mod file;
17pub use file::*;
18
19mod summary;
20pub use summary::*;
21
22
23#[derive(Debug, PartialEq, Deserialize)]
24pub struct CoverageReport<'a> {
25    /// The version of the exported data.
26    pub version: &'a str,
27    /// The type of exported data. Must be set to llvm.coverage.json.export.
28    #[serde(rename = "type")]
29    pub export_type: &'a str,
30    /// This is the actual coverage data. According to the [LLVM source code](https://github.com/llvm/llvm-project/blob/309d55140c46384b6de7a7573206cbeba3f7077f/llvm/tools/llvm-cov/CoverageExporterJson.cpp#L17C22-L17C69)
31    /// this is a "homogeneous array of one or more export objects", however, in practice, it contains only one element.
32    pub data: Vec<ExportObject<'a>>,
33}
34
35impl<'a> CoverageReport<'a> {
36
37    pub fn from_str(s: &str) -> Result<CoverageReport, serde_json::Error> {
38        Ok(serde_json::from_str(s)?)
39    }
40
41}
42
43
44#[derive(Debug, PartialEq, Deserialize)]
45pub struct ExportObject<'a> {
46    /// Summary of all coverage data in this export.
47    #[serde(rename = "totals")]
48    pub summary: Summary,
49    /// Per file metrics.
50    #[serde(borrow)]
51    pub files: Vec<FileMetrics<'a>>,
52    #[serde(borrow)]
53    pub functions: Vec<FunctionMetrics<'a>>,
54}