Function rust_code_analysis::action[][src]

pub fn action<T: Callback>(
    lang: &LANG,
    source: Vec<u8>,
    path: &Path,
    pr: Option<Arc<PreprocResults>>,
    cfg: T::Cfg
) -> T::Res
Expand description

Runs a function, which implements the Callback trait, on a code written in one of the supported languages.

Examples

The following example dumps to shell every metric computed using the dummy source code.

use std::path::PathBuf;

use rust_code_analysis::{action, Callback, LANG, Metrics, MetricsCfg};

let source_code = "int a = 42;";
let language = LANG::Cpp;

// The path to a dummy file used to contain the source code
let path = PathBuf::from("foo.c");
let source_as_vec = source_code.as_bytes().to_vec();

// Configuration options used by the function which computes the metrics
let cfg = MetricsCfg {
    path,
};

action::<Metrics>(&language, source_as_vec, &cfg.path.clone(), None, cfg);