Skip to main content

Module wire

Module wire 

Source
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 f64 and carry the non_finite (de)serialization: a non-finite value (NaN/±∞, meaning “not applicable”) serializes to a null uniformly across formats — native null in JSON/YAML/CBOR, an omitted key in TOML — and deserializes back to f64::NAN (#531). Finite values pass through unchanged, so the round-trip is symmetric and needs no Option.
  • CodeMetrics elides unselected metrics (each is an Option skipped when None); on read, a present key ⇒ selected, absent ⇒ unselected. CodeMetrics::selected reconstructs the MetricSet from the present keys.

Structs§

Abc
Wire form of the Abc metric.
CodeMetrics
Wire form of crate::spaces::CodeMetrics.
Cognitive
Wire form of the Cognitive metric.
Cyclomatic
Wire form of the Cyclomatic metric.
CyclomaticModified
Wire form of the modified-cyclomatic sub-record.
FuncSpace
Wire form of crate::spaces::FuncSpace — a recursive metric tree.
FunctionSpan
Wire form of crate::FunctionSpan.
Halstead
Wire form of the Halstead metric suite.
Loc
Wire form of the Loc metric suite.
Mi
Wire form of the Mi (maintainability index) metric.
Nargs
Wire form of the NArgs metric.
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 Tokens metric.
Wmc
Wire form of the Wmc (weighted-methods-per-class) metric.