Skip to main content

MetricsOptions

Struct MetricsOptions 

Source
#[non_exhaustive]
pub struct MetricsOptions { pub exclude_tests: bool, pub metrics: MetricSet, }
Expand description

Per-traversal options for [metrics_with_options].

Marked #[non_exhaustive] so future option fields can land additively. Downstream callers must construct via the builder methods rather than struct-literal syntax (rustc rejects external struct literals on non-exhaustive types with E0639, including the ..Default::default() spread form). The defaults preserve every metric value emitted by the pre-#182 [metrics] entry point.

use big_code_analysis::MetricsOptions;
let opts = MetricsOptions::default().with_exclude_tests(true);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§exclude_tests: bool

When true, the traversal asks the language module to skip test-only subtrees (e.g. Rust #[test] / #[cfg(test)] functions and modules). Only languages that override the internal should_skip_subtree hook honor this; others ignore the flag.

§metrics: MetricSet

Which metrics to compute. Defaults to MetricSet::all — every metric is enabled, matching the pre-#257 behaviour. Restrict via MetricsOptions::with_only.

Implementations§

Source§

impl MetricsOptions

Source

pub fn with_exclude_tests(self, exclude_tests: bool) -> Self

Builder-style setter for MetricsOptions::exclude_tests.

Provided because MetricsOptions is #[non_exhaustive] — the struct-literal form is unavailable to downstream crates, so external callers chain MetricsOptions::default() .with_exclude_tests(true) instead.

Source

pub fn with_only(self, metrics: &[Metric]) -> Self

Restrict computation to the given metrics. Metrics outside this set are skipped during the walk; their Stats fields on CodeMetrics remain at their Default value and are elided from the Serialize output. Pass an empty slice to disable every metric (the walker still runs and produces the space tree, but no metric values are populated).

§Dependencies

Derived metrics implicitly pull in the inputs they require:

This auto-resolution is silent: a caller asking for Mi alone gets a populated Mi value, not a zero. See Metric::dependencies for the source of truth.

§Examples
use big_code_analysis::{Metric, MetricsOptions};

// Compute LoC only.
let _opts = MetricsOptions::default().with_only(&[Metric::Loc]);

// Compute Mi: Loc + Cyclomatic + Halstead are auto-added.
let _opts = MetricsOptions::default().with_only(&[Metric::Mi]);
Source

pub fn with_metric_set(self, metrics: MetricSet) -> Self

Restrict computation to an already-resolved MetricSet.

§Caller responsibility

The input set MUST be closed under Metric::dependencies before it reaches this builder. Use MetricSet::from_slice_with_deps to construct a dependency-closed set from a slice of metric names, or call MetricsOptions::with_only (which performs the closure internally) when you have a &[Metric] rather than a pre-built set.

This builder is NOT equivalent to MetricsOptions::with_only: with_only runs the closure resolver; with_metric_set consumes the set verbatim and trusts the caller. The two methods are interchangeable only when the input is already closed.

§Pitfall

Passing an unresolved set silently corrupts derived metrics — the walker computes Metric::Mi or Metric::Wmc using zero-valued dependency inputs and emits a number with no error. For example:

use big_code_analysis::{Metric, MetricSet, MetricsOptions};

// WRONG: `Mi` selected without its dependencies — the
// resulting MI value is garbage (formula divides by a
// zero-valued Loc / Halstead).
let bad = MetricSet::empty().with(Metric::Mi);
let _opts = MetricsOptions::default().with_metric_set(bad);

// RIGHT: closure resolved upstream; `with_metric_set`
// attaches the already-closed set.
let good = MetricSet::from_slice_with_deps(&[Metric::Mi]);
let _opts = MetricsOptions::default().with_metric_set(good);

The closure-resolved form above is equivalent to MetricsOptions::with_only(&[Metric::Mi]) — prefer that builder if you don’t already have a MetricSet.

Trait Implementations§

Source§

impl Clone for MetricsOptions

Source§

fn clone(&self) -> MetricsOptions

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 MetricsOptions

Source§

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

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

impl Default for MetricsOptions

Source§

fn default() -> MetricsOptions

Returns the “default value” for a type. Read more
Source§

impl PartialEq for MetricsOptions

Source§

fn eq(&self, other: &MetricsOptions) -> 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 MetricsOptions

Source§

impl Eq for MetricsOptions

Source§

impl StructuralPartialEq for MetricsOptions

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