Skip to main content

Module string_map

Module string_map 

Source
Expand description

Substrate primitive over std::collections::BTreeMap<String, String> — the ONE substrate owner of the <map>.insert(<k>.to_string(), <v>.to_string()) string-string insertion shape every K8s-carrier writer (ObjectMeta annotations / labels, ConfigMap data) restates by hand at the &str × &str → BTreeMap write boundary.

Receiver-shape peer of crate::json_object::JsonMapStrExt::insert_str on the “insert a string at a string key” write axis, partitioned by CARRIER TYPE:

  • crate::json_object::JsonMapStrExt::insert_str — the serde_json::Map<String, Value> receiver used by every JSON-shaped metadata.annotations / label map / spec-body slot the reconciler emits to K8s through SSA-time serde_json::Value bodies.
  • BTreeMapStrExt::insert_str (this trait) — the BTreeMap<String, String> receiver used by every K8s-canonical ObjectMeta annotations / labels slot AND every ConfigMap .data slot the workspace stamps through the kube-rs typed API surface (which reifies ObjectMeta.annotations: Option<BTreeMap<String, String>> verbatim).

The two traits deliberately share the insert_str method name AND the (impl Into<String>, impl Into<String>) argument shape so a caller who imports either substrate reaches the same-shape write call at the same-name method, regardless of whether the receiver is the JSON-side Map<String, Value> or the K8s-typed-API-side BTreeMap<String, String>. A future new carrier (e.g. a HashMap<String, String> receiver for a lightweight fixture map, or a secrecy::Secret<String> value-slot for encrypted secret payloads) adds one impl arm here without splitting the substrate into a third trait.

Pre-lift the shape was hand-authored at THREE production sites across two workspace crates past the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold:

  • tatara-pool-reconciler::controller_pool::build_member_process × 2 — the pool-membership annotation seed stamping annotations::POOL + annotations::POOL_SLOT into the fresh member Process’s metadata.annotations map right after Process:: new. Both restated the same <map>.insert(<key>.to_string(), <val>.to_string()) shape.
  • tatara-export-worker::write_receipt × 1 — the receipt-CM .data seed stamping the (configmap-key, payload) pair into the fresh BTreeMap right before the crate::configmap::with_data composer wraps it as a ConfigMap wire body.

All three sites walked the SAME two-position insert shape verbatim, differing only in the &str / &'static str key + the &str / numeric-.to_string() value at each callsite. Post-lift each callsite reads <map>.insert_str(<key>, <val>) and the string- string write shape lives at ONE substrate owner here.

§Naming — insert_str, not insert

Same discipline as the sibling crate::json_object::JsonMapStrExt::insert_str — the trait method deliberately does NOT collide with the inherent BTreeMap::insert (which takes (String, String) positionally). A name collision would let a caller who has BTreeMapStrExt in scope resolve to the inherent method by accident (inherent methods win over trait methods in method resolution) and silently drop the Into<String> coerce on either slot. The _str suffix names the intent: both slots project the caller’s borrowed handle into an owned String at the substrate, not at every callsite.

Theory anchor: THEORY.md §VI.1 (generation over composition — the <map>.insert(<k>.to_string(), <v>.to_string()) shape recurred at three hand-authored production sites across two workspace crates past the ★★ PRIME-DIRECTIVE ≥ 2 duplication trigger, and is lifted to ONE substrate owner here). THEORY.md §II.1 invariant 5 (composition preserves proofs — a regression that drifts the write shape at ONE consumer surfaces at the substrate pin rather than as silent per-emit skew across every K8s-carrier annotations / labels / ConfigMap-data writer).

Traits§

BTreeMapStrExt
Substrate extension trait over BTreeMap<String, String> — the ONE substrate owner of the <map>.insert(<k>.to_string(), <v>.to_string ()) string-string insertion shape every K8s-carrier writer (ObjectMeta annotations / labels, ConfigMap .data) hand-authored at the callsite pre-lift.