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 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 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.
Vcsvcs-git
Wire form of crate::vcs::Stats — per-file change-history metrics.
VcsReportvcs-git
Wire form of the file-ranking change-history report (issue #328) — the single serialized shape shared by bca vcs, POST /vcs, and the Python vcs.rank() (#664).
VcsReportFilevcs-git
Wire form of one ranked file in a VcsReport: its repository- relative path plus the always-slim Vcs block, nested under a vcs key like every other metric group (issue #684).
VcsTrendvcs-git
Wire form of a historical metric trend (issue #333) — the single serialized shape shared by bca vcs trend, POST /vcs/trend, and the Python vcs_trend().
VcsTrendDeltavcs-git
Wire form of one file’s risk-score movement across the trend.
VcsTrendDeltasvcs-git
Wire form of the improving / regressing delta summary.
VcsTrendPointvcs-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_of leads; the metrics sit under a nested vcs key (issue #684), the same always-slim Vcs row every other endpoint emits. The four constant stamps are carried once on the enclosing VcsTrend, 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 FuncSpace and Ops will serialize.