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/Ops trees). 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.
§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. - Wmc
- Wire form of the
Wmc(weighted-methods-per-class) metric.