Skip to main content

LcovData

Struct LcovData 

Source
pub struct LcovData {
    pub functions: HashMap<PathBuf, Vec<FunctionCoverage>>,
    pub total_lines: usize,
    pub lines_hit: usize,
    /* private fields */
}
Expand description

Parsed LCOV coverage data.

Contains all coverage information extracted from an LCOV file, organized by file path for efficient lookup. Includes a pre-built index for O(1) function coverage lookups.

§Thread Safety

The coverage_index is wrapped in Arc for lock-free sharing across threads during parallel analysis operations.

§Example

use std::path::Path;
use debtmap::risk::lcov::{parse_lcov_file, LcovData};

let data = parse_lcov_file(Path::new("coverage.info"))?;
println!("Total lines: {}", data.total_lines);
println!("Lines hit: {}", data.lines_hit);
println!("Coverage: {:.1}%", data.get_overall_coverage());

Fields§

§functions: HashMap<PathBuf, Vec<FunctionCoverage>>

Map of file paths to their function coverage data

§total_lines: usize

Total number of executable lines across all files

§lines_hit: usize

Number of lines that were executed

Implementations§

Source§

impl LcovData

Source

pub fn with_loc_counter(self, loc_counter: LocCounter) -> Self

Set the LOC counter to use for consistent line counting.

§Arguments
  • loc_counter - The LOC counter instance to use
§Returns

Self with the LOC counter set.

Source

pub fn loc_counter(&self) -> Option<&LocCounter>

Get the LOC counter instance if set.

Source

pub fn recalculate_with_loc_counter(&mut self)

Recalculate total lines using LOC counter for consistency.

This ensures coverage denominator matches the LOC count used elsewhere. Useful when you want the coverage percentage to align with LOC-based metrics.

Source

pub fn get_function_coverage( &self, file: &Path, function_name: &str, ) -> Option<f64>

Get function coverage using O(1) indexed lookup.

This method uses the pre-built coverage index for fast lookups, avoiding the O(n) linear search through function arrays.

§Arguments
  • file - Path to the source file
  • function_name - Name of the function
§Returns

Coverage as a fraction (0.0 to 1.0), or None if not found.

Source

pub fn get_function_coverage_with_line( &self, file: &Path, function_name: &str, line: usize, ) -> Option<f64>

Get function coverage with line number fallback using O(log n) indexed lookup.

Tries exact function name match first (O(1)), then falls back to line-based lookup (O(log n)) if needed.

§Arguments
  • file - Path to the source file
  • function_name - Name of the function
  • line - Line number for fallback lookup
§Returns

Coverage as a fraction (0.0 to 1.0), or None if not found.

Source

pub fn get_function_coverage_with_bounds( &self, file: &Path, function_name: &str, _start_line: usize, _end_line: usize, ) -> Option<f64>

Get function coverage using exact boundaries from AST analysis.

This is more accurate than guessing boundaries from LCOV data alone. Uses path normalization (Spec 201) and function name matching (Spec 202) to find the correct function even when names don’t match exactly.

Integration of Specs 201, 202, and 203:

  • Uses path normalization (Spec 201) to find matching files
  • Uses function name matching (Spec 202) to find matching functions
  • Returns 0.0 instead of None when LCOV provided but function not found (Spec 203)
  • Logs diagnostics when DEBTMAP_COVERAGE_DEBUG is set (Spec 203)
§Arguments
  • file - Path to the source file
  • function_name - Name of the function
  • _start_line - Start line (reserved for future use)
  • _end_line - End line (reserved for future use)
§Returns

Coverage as a fraction (0.0 to 1.0), or None if file not in LCOV data. Returns Some(0.0) if file is in LCOV but function not found.

Source

pub fn get_overall_coverage(&self) -> f64

Get overall coverage percentage.

§Returns

Overall coverage as a percentage (0.0 to 100.0).

Source

pub fn get_file_coverage(&self, file: &Path) -> Option<f64>

Get coverage percentage for a specific file.

§Arguments
  • file - Path to the source file
§Returns

Coverage as a fraction (0.0 to 1.0), or None if file not found.

Source

pub fn get_function_uncovered_lines( &self, file: &Path, function_name: &str, line: usize, ) -> Option<Vec<usize>>

Get uncovered lines for a function using O(1) indexed lookup.

§Arguments
  • file - Path to the source file
  • function_name - Name of the function
  • line - Line number for fallback lookup
§Returns

List of uncovered line numbers, or None if function not found.

Source

pub fn batch_get_function_coverage( &self, queries: &[(PathBuf, String, usize)], ) -> Vec<Option<f64>>

Batch process coverage queries for multiple functions in parallel.

This is more efficient when querying coverage for many functions at once.

§Arguments
  • queries - List of (file, function_name, line) tuples
§Returns

Vector of coverage values in the same order as queries.

Source

pub fn get_all_file_coverages(&self) -> HashMap<PathBuf, f64>

Get coverage statistics for all files in parallel.

§Returns

HashMap mapping file paths to their coverage (as fractions 0.0 to 1.0).

Source§

impl LcovData

Source

pub fn new() -> Self

Create a new empty LcovData instance.

§Example
let data = LcovData::new();
assert_eq!(data.total_lines, 0);
assert!(data.functions.is_empty());
Source

pub fn build_index(&mut self)

Build the coverage index from current function data.

This should be called after modifying the functions HashMap to ensure the index is up to date for O(1) lookups.

Trait Implementations§

Source§

impl Clone for LcovData

Source§

fn clone(&self) -> LcovData

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LcovData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LcovData

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> EnsureExt<T> for T

Source§

fn ensure<P, E>(self, predicate: P, error: E) -> Validation<T, NonEmptyVec<E>>
where P: Predicate<T>,

Validate that this value satisfies the given predicate. Read more
Source§

fn ensure_with<P, E, F>( self, predicate: P, error_fn: F, ) -> Validation<T, NonEmptyVec<E>>
where P: Predicate<T>, F: FnOnce(&T) -> E,

Validate with an error-generating function. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more