Skip to main content

MetricsOptions

Struct MetricsOptions 

Source
#[non_exhaustive]
pub struct MetricsOptions { /* private fields */ }
Expand description

Per-traversal options for analyze / Ast::metrics.

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 analyze entry point.

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

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_count_cyclomatic_try(self, count: bool) -> Self

Builder-style setter for MetricsOptions::count_cyclomatic_try.

Pass false to stop Rust’s ? operator from contributing to cyclomatic complexity (standard and modified). The default is true, which keeps every published metric value unchanged (#409). Inert for non-Rust languages, none of which emit the try_expression grammar node.

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 the metrics in metrics, closing the set under Metric::dependencies before storing it.

Like MetricsOptions::with_only, a derived metric pulls in the inputs it needs: passing MetricSet::empty().with(Metric::Mi) also selects Metric::Loc, Metric::Cyclomatic, and Metric::Halstead, so the maintainability index is computed from real inputs rather than zero-valued defaults (#743). The resolution is idempotent: an already-closed set is stored unchanged.

Use this builder when you already hold a MetricSet; reach for MetricsOptions::with_only when you have a &[Metric].

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

// `Mi` alone — Loc + Cyclomatic + Halstead are auto-added so the
// resulting MI value is meaningful.
let set = MetricSet::empty().with(Metric::Mi);
let _opts = MetricsOptions::default().with_metric_set(set);

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

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() -> Self

Defaults preserve every metric value emitted by the pre-#182 analyze entry point: every metric selected, tests included, and Rust ? counted toward cyclomatic (#409).

Source§

impl Eq for MetricsOptions

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