Skip to main content

analyze

Function analyze 

Source
pub fn analyze(
    source: Source<'_>,
    options: MetricsOptions,
) -> Result<FuncSpace, MetricsError>
Expand description

Compute every metric for a Source.

This is the recommended library entry point. Unlike the deprecated [metrics] / [metrics_with_options] family it does not conflate the top-level FuncSpace::name with a filesystem path: callers supply an explicit Source::name and an optional Source::preproc_path for C++ preprocessor lookup.

options controls per-traversal flags (e.g. MetricsOptions::default().with_exclude_tests(true) to elide Rust #[test] / #[cfg(test)] subtrees).

§Errors

The return type carries MetricsError::EmptyRoot for forward compatibility, but the walker always pushes a synthetic top-level SpaceKind::Unit FuncSpace before walking, so this function does not return Err in practice today (see the variant doc).

§Examples

Analysing an in-memory snippet without constructing a Path:

use big_code_analysis::{analyze, MetricsOptions, Source, LANG};

let space = analyze(
    Source::new(LANG::Rust, b"fn main() { let x = 1 + 2; }")
        .with_name(Some("snippet.rs".to_owned())),
    MetricsOptions::default(),
)
.expect("snippet has a top-level FuncSpace");
assert_eq!(space.name.as_deref(), Some("snippet.rs"));