#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.exclude_tests: boolWhen 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: MetricSetWhich 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
impl MetricsOptions
Sourcepub fn with_exclude_tests(self, exclude_tests: bool) -> Self
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.
Sourcepub fn with_only(self, metrics: &[Metric]) -> Self
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:
Metric::MiaddsMetric::Loc,Metric::Cyclomatic,Metric::Halstead.Metric::WmcaddsMetric::CyclomaticandMetric::Nom.
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]);Sourcepub fn with_metric_set(self, metrics: MetricSet) -> Self
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
impl Clone for MetricsOptions
Source§fn clone(&self) -> MetricsOptions
fn clone(&self) -> MetricsOptions
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MetricsOptions
impl Debug for MetricsOptions
Source§impl Default for MetricsOptions
impl Default for MetricsOptions
Source§fn default() -> MetricsOptions
fn default() -> MetricsOptions
Source§impl PartialEq for MetricsOptions
impl PartialEq for MetricsOptions
Source§fn eq(&self, other: &MetricsOptions) -> bool
fn eq(&self, other: &MetricsOptions) -> bool
self and other values to be equal, and is used by ==.impl Copy for MetricsOptions
impl Eq for MetricsOptions
impl StructuralPartialEq for MetricsOptions
Auto Trait Implementations§
impl Freeze for MetricsOptions
impl RefUnwindSafe for MetricsOptions
impl Send for MetricsOptions
impl Sync for MetricsOptions
impl Unpin for MetricsOptions
impl UnsafeUnpin for MetricsOptions
impl UnwindSafe for MetricsOptions
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> 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.