Skip to main content

Metric

Enum Metric 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Cognitive

Cognitive complexity (crate::cognitive::Stats).

§

Cyclomatic

Cyclomatic complexity (crate::cyclomatic::Stats).

§

Halstead

§

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

§

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

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Metric

Source§

fn clone(&self) -> Metric

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Metric

Source§

impl Debug for Metric

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Metric

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Metric

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Metric

Source§

impl FromStr for Metric

Source§

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

The associated error which can be returned from parsing.
Source§

impl Hash for Metric

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Metric

Source§

fn cmp(&self, other: &Metric) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Metric

Source§

fn eq(&self, other: &Metric) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Metric

Source§

fn partial_cmp(&self, other: &Metric) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Metric

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Metric

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<N> NodeTrait for N
where N: Copy + Ord + Hash,

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.