Expand description
Plain, Deserialize-capable data-transfer structs mirroring the
serialized metric wire shape. The compute types’ Serialize impls
delegate here, making these the single definition of the JSON / YAML /
TOML / CBOR output format and the canonical way to read bca output
back (serde_json::from_str::<wire::FuncSpace>(…)).
Plain, public data-transfer structs mirroring the serialized metric
wire shape — the single source of truth for the JSON / YAML / TOML /
CBOR output format and the only Deserialize-capable view of it.
The compute types (crate::spaces::FuncSpace,
crate::spaces::CodeMetrics, the per-metric Stats, crate::Ops,
crate::FunctionSpan) store raw state (e.g. Halstead keeps four
operator/operand counts and derives volume/difficulty/… on demand;
cognitive keeps a sum and a hidden space count and derives
average). Their serialized form is therefore a projection: a flat
record of already-derived values, several of which (the averages,
ratios, and Halstead/MI scores) cannot be inverted back to the private
state. A plain #[derive(Deserialize)] on the compute types is thus
impossible.
This module defines a parallel struct per metric and per container
whose fields are exactly the serialized fields, deriving both
Serialize and Deserialize. The compute types’ own Serialize
impls delegate here (via the From<&Compute> projections below), so
there is exactly one definition of the wire shape; deserialization
reads into these wire structs and round-trips byte-for-byte.
Delegation materializes an owned projection per serialize (a deep clone
for the recursive FuncSpace tree). This is the deliberate cost
of a single source of truth that also round-trips: a borrowing
serialize-only mirror would double the struct set and could not derive
Deserialize. Serialization runs once per file and the projection is
dropped immediately, so it is not on a tight inner loop.
Ops is the one measured exception: it serializes through a
borrowed mirror instead, for the reasons the private ops_view
submodule documents.
§Field conventions
- Integer-valued metrics (counts, sums, min/max) are
u64(#530). - Derived / ratio / average fields are
f64and carry thenon_finite(de)serialization: a non-finite value (NaN/±∞, meaning “not applicable”) serializes to a null uniformly across formats — nativenullin JSON/YAML/CBOR, an omitted key in TOML — and deserializes back tof64::NAN(#531). Finite values pass through unchanged, so the round-trip is symmetric and needs noOption. CodeMetricselides unselected metrics (each is anOptionskipped whenNone); on read, a present key ⇒ selected, absent ⇒ unselected.CodeMetrics::selectedreconstructs theMetricSetfrom the present keys.
Structs§
- Abc
- Wire form of the
Abcmetric. - Code
Metrics - Wire form of
crate::spaces::CodeMetrics. - Cognitive
- Wire form of the
Cognitivemetric. - Cyclomatic
- Wire form of the
Cyclomaticmetric. - Cyclomatic
Modified - Wire form of the modified-cyclomatic sub-record.
- Func
Space - Wire form of
crate::spaces::FuncSpace— a recursive metric tree. - Function
Span - Wire form of
crate::FunctionSpan. - Halstead
- Wire form of the
Halsteadmetric suite. - Loc
- Wire form of the
Locmetric suite. - Mi
- Wire form of the
Mi(maintainability index) metric. - Nargs
- Wire form of the
NArgsmetric. - Nexits
- Wire form of the
Nexits(exit-points) metric. - Nom
- Wire form of the
Nom(number-of-methods) metric. - Npa
- Wire form of the
Npa(number-of-public-attributes) metric. - Npm
- Wire form of the
Npm(number-of-public-methods) metric. - Ops
- Wire form of
crate::Ops— a recursive operator/operand tree. - Tokens
- Wire form of the
Tokensmetric. - Vcs
vcs-git - Wire form of
crate::vcs::Stats— per-file change-history metrics. - VcsReport
vcs-git - Wire form of the file-ranking change-history report (issue #328) —
the single serialized shape shared by
bca vcs,POST /vcs, and the Pythonvcs.rank()(#664). - VcsReport
File vcs-git - Wire form of one ranked file in a
VcsReport: its repository- relative path plus the always-slimVcsblock, nested under avcskey like every other metric group (issue #684). - VcsTrend
vcs-git - Wire form of a historical metric trend (issue #333) — the single
serialized shape shared by
bca vcs trend,POST /vcs/trend, and the Pythonvcs_trend(). - VcsTrend
Delta vcs-git - Wire form of one file’s risk-score movement across the trend.
- VcsTrend
Deltas vcs-git - Wire form of the improving / regressing delta summary.
- VcsTrend
Point vcs-git - Wire form of one sampled point in a historical metric trend (issue
#333): the sample timestamp plus the file’s VCS block at that moment.
as_ofleads; the metrics sit under a nestedvcskey (issue #684), the same always-slimVcsrow every other endpoint emits. The four constant stamps are carried once on the enclosingVcsTrend, never repeated per point (issue #635). - Wmc
- Wire form of the
Wmc(weighted-methods-per-class) metric.
Constants§
- MAX_
SPACE_ SERIALIZE_ DEPTH - Greatest space-nesting depth
FuncSpaceandOpswill serialize.