pub fn action<T: Callback>(
lang: &LANG,
source: Vec<u8>,
path: &Path,
pr: Option<Arc<PreprocResults>>,
cfg: T::Cfg,
) -> Result<T::Res, MetricsError>Expand description
Runs a function, which implements the Callback trait,
on a code written in one of the supported languages.
§Errors
Returns MetricsError::LanguageDisabled when lang
names a language whose per-language Cargo feature is not
enabled in the current build (see the [features] table
in the root Cargo.toml). All other failure modes are
reported through the callback’s own T::Res.
§Examples
The following example dumps to shell every metric computed using the dummy source code.
use std::path::PathBuf;
use big_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::new(path);
action::<Metrics>(&language, source_as_vec, &cfg.path.clone(), None, cfg)
.expect("cpp feature enabled");