Skip to main content

Metric

Enum Metric 

Source
#[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
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).

§

Exit

Exit-point count (crate::exit::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. 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.

Source

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 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 Debug for Metric

Source§

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

Formats the value using the given formatter. 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 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. 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

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 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 Copy for Metric

Source§

impl Eq for Metric

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> 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<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> 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.