#[non_exhaustive]pub enum Metric {
Show 13 variants
Cognitive,
Cyclomatic,
Halstead,
Loc,
Nom,
Tokens,
Nargs,
Nexits,
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.
Ord follows declaration order, not the Display
spelling. It exists so Metric can key a BTreeSet — notably the
suppression scope (SuppressionScope::Some) — with a deterministic,
stable iteration order across runs. Do not rely on the ordering being
alphabetical; reorder the variants only with a deliberate review of
every serialized BTreeSet<Metric> snapshot.
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).
Nexits
Exit-point count (crate::nexits::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. Every
metric uses one canonical spelling end-to-end:
Metric::Nexits is "nexits" in Display, in this table,
and as the JSON output key (the CodeMetrics::Serialize impl
in src/spaces.rs).
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 and averaged metrics 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 result. Callers
typically reach this through
MetricsOptions::with_only,
which auto-resolves the closure transparently.
Sourcepub fn suppressible() -> impl Iterator<Item = Metric>
pub fn suppressible() -> impl Iterator<Item = Metric>
Every metric except Metric::Tokens, in declaration order.
tokens is the one metric with no configurable threshold, so it
is the one metric that cannot be named in a suppression marker
(bca: suppress(tokens) is rejected). This is the single source
of truth for the suppressible vocabulary: the suppression
parser’s “known metrics” hint and the threshold-name resolver
both derive from it rather than hardcoding the list.
Trait Implementations§
impl Copy for Metric
Source§impl<'de> Deserialize<'de> for Metric
impl<'de> Deserialize<'de> for Metric
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for Metric
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. Every metric has exactly
one accepted spelling, matching its Display form, NAMES
entry, and JSON output key.
Source§type Err = ParseMetricError
type Err = ParseMetricError
Source§impl Ord for Metric
impl Ord for Metric
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Metric
impl PartialOrd 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> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.