#[non_exhaustive]pub enum Metric {
Show 13 variants
Cognitive,
Cyclomatic,
Halstead,
Loc,
Nom,
Tokens,
NArgs,
Exit,
Abc,
Npm,
Npa,
Mi,
Wmc,
}Expand description
One metric computed by the analysis walker.
Pass a slice of these to
MetricsOptions::with_only to
restrict computation to the listed metrics.
#[non_exhaustive] so future metrics can land additively. Use
match against the existing variants and either a wildcard arm or
the m if !MetricSet::all().contains(m) guard to stay
forwards-compatible.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Cognitive
Cognitive complexity (crate::cognitive::Stats).
Cyclomatic
Cyclomatic complexity (crate::cyclomatic::Stats).
Halstead
Halstead (crate::halstead::Stats).
Loc
LoC family (crate::loc::Stats).
Nom
Number of methods (crate::nom::Stats).
Tokens
Token counts (crate::tokens::Stats).
NArgs
Number of arguments (crate::nargs::Stats).
Exit
Exit-point count (crate::exit::Stats).
Abc
ABC (crate::abc::Stats).
Npm
Number of public methods (crate::npm::Stats).
Npa
Number of public attributes (crate::npa::Stats).
Mi
Maintainability index (crate::mi::Stats). Derived metric:
selecting only Mi via
MetricsOptions::with_only
also pulls in Metric::Loc, Metric::Cyclomatic, and
Metric::Halstead.
Wmc
Weighted methods per class (crate::wmc::Stats). Derived
metric: selecting Wmc also pulls in Metric::Cyclomatic
and Metric::Nom.
Implementations§
Source§impl Metric
impl Metric
Sourcepub const NAMES: &'static [&'static str]
pub const NAMES: &'static [&'static str]
Canonical user-facing name for each metric — the single
source of truth shared by the Python bindings’
bca.METRIC_NAMES constant, the unknown metric: <bad>; valid: … error message, and any downstream Rust consumer
that parses user input into a MetricSet.
Each entry round-trips through Metric::from_str. The table uses the
JSON-output-key spelling for Metric::Exit ("nexits",
matching the CodeMetrics::Serialize impl in
src/spaces.rs) rather than the fmt::Display spelling
("exit"); both parse to Metric::Exit via the alias
arm in FromStr, but the canonical spelling exposed here
is the JSON one so callers see the same name in
Metric::NAMES, in the output dict, and in error
messages.
Alphabetised. The drift between this table and the
FromStr arms (or the Metric enum itself) is guarded by
names_table_parses_to_every_variant and
names_table_is_alphabetised in the test module below.
Sourcepub const fn dependencies(self) -> &'static [Metric]
pub const fn dependencies(self) -> &'static [Metric]
Returns the slice of metrics this metric depends on.
Derived metrics (Mi, Wmc) consume the outputs of other
metrics during the finalize step; selecting one without its
dependencies would leave the dependency’s Stats at default
(zero) values and silently corrupt the derived value. Callers
typically reach this through
MetricsOptions::with_only,
which auto-resolves the closure transparently.
Trait Implementations§
Source§impl FromStr for Metric
impl FromStr for Metric
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Parse a Metric from its fmt::Display spelling.
Strict lowercase: "Loc" is rejected. The single alias is
"nexits", which parses to Metric::Exit — this matches
the JSON output key the metric’s Stats serialises under,
so downstream consumers can use either the enum-Display
spelling or the JSON-key spelling interchangeably.
Source§type Err = ParseMetricError
type Err = ParseMetricError
impl Copy for Metric
impl Eq for Metric
impl StructuralPartialEq for Metric
Auto Trait Implementations§
impl Freeze for Metric
impl RefUnwindSafe for Metric
impl Send for Metric
impl Sync for Metric
impl Unpin for Metric
impl UnsafeUnpin for Metric
impl UnwindSafe for Metric
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.