pub trait MappingExt {
// Required methods
fn insert_str_key(&mut self, key: &str, value: Value) -> Option<Value>;
fn insert_string<V: Into<String>>(
&mut self,
key: &str,
value: V,
) -> Option<Value>;
fn insert_number<N: Into<Number>>(
&mut self,
key: &str,
value: N,
) -> Option<Value>;
fn insert_mapping(&mut self, key: &str, value: Mapping) -> Option<Value>;
fn insert_sequence(&mut self, key: &str, value: Vec<Value>) -> Option<Value>;
fn insert_singleton_mapping_sequence(
&mut self,
key: &str,
value: Mapping,
) -> Option<Value>;
fn entry_str_key(&mut self, key: &str) -> Entry<'_>;
fn insert_str_key_if_some(
&mut self,
key: &str,
value: Option<&Value>,
) -> Option<Value>;
fn entry_or_default_mapping(&mut self, key: &str) -> Option<&mut Mapping>;
fn entry_or_default_sequence(
&mut self,
key: &str,
) -> Option<&mut Vec<Value>>;
}Expand description
Extension methods on serde_yaml::Mapping that lift the per-key
scalar-promotion boilerplate every K8s-artifact-emitter across
caixa-mesh, caixa-flux, caixa-helm, and caixa-core::render
carries: the canonical mapping.insert(Value::String(key.into()), value) three-liner the schema-key axis of every emitted YAML
document tunnels a &'static str key axis-name through.
Five methods form the primitive quintuple — one per non-Null
primitive serde_yaml::Value variant the K8s-artifact-emit
surface actually reaches for as a leaf payload:
Self::insert_str_key— insert with a&strkey and any fully-builtserde_yaml::Value. The building block every other renderer helper (yaml_string_mapping,label_selector,kube_resource_skeleton,single_field_overlay) composes on top of.Self::insert_string— insert with a&strkey and anInto<String>value that gets auto-promoted toserde_yaml::Value::String. The string-scalar-valued-field shape every schema-typedapiVersion/kind/metadata.namespace/port.protocol/hostname/path.valueaxis emission uses — collapses the two-stepinsert_str_key(K, Value::String(V.into()))boilerplate onto one direct call.Self::insert_number— insert with a&strkey and anInto<serde_yaml::Number>value that gets auto-promoted toserde_yaml::Value::Number. The integer-scalar-valued-field shape every schema-typedport/targetPort/attempts/maxFailures/hostPortaxis emission uses — collapses the two-stepinsert_str_key(K, Value::Number(N.into()))boilerplate onto one direct call.Self::insert_mapping— insert with a&strkey and aserde_yaml::Mappingvalue that gets auto-promoted toserde_yaml::Value::Mapping. The nested-Mapping-valued-field shape every schema-typedmetadata/spec/spec.rules[].path/toPorts[].rulessub-block emission uses — collapses the two-stepinsert_str_key(K, Value::Mapping(m))boilerplate onto one direct call.Self::insert_sequence— insert with a&strkey and aVec<serde_yaml::Value>value that gets auto-promoted toserde_yaml::Value::Sequence. The list-shape-valued-field shape every schema-typedspec.ingress[].fromEndpoints/spec.ingress[].toPorts/spec.hostnames/spec.ruleslist emission uses — collapses the two-stepinsert_str_key(K, Value::Sequence(v))boilerplate onto one direct call.
A sibling method — Self::entry_str_key — closes the entry-API
twin of Self::insert_str_key on the same &str → Value::String
key-promotion axis: the serde_yaml::Mapping::entry method’s
Value parameter demands the same Value::String(<K>.into())
wrapping every fresh-emit site’s insert_str_key call closes, but
on the idempotent-upsert axis (where callers compose
.or_insert(...) / .or_insert_with(...) / .and_modify(...) /
.or_default() on the returned entry handle) rather than the
fresh-emit axis. Same key-promotion contract, different downstream
API surface — so a future rebrand of the promotion (e.g. to
serde_yaml::Value::Tagged under a K8s Server-Side-Apply typed-
field-ownership axis) reaches both fresh-emit and upsert sites
through one lift.
See each method’s docstring for its compounding rationale.
Required Methods§
Sourcefn insert_str_key(&mut self, key: &str, value: Value) -> Option<Value>
fn insert_str_key(&mut self, key: &str, value: Value) -> Option<Value>
Insert (key, value) into self with key promoted to a
serde_yaml::Value::String. Returns the prior value at that
key, mirroring serde_yaml::Mapping::insert.
The canonical shape ~48 call sites across the caixa-side
renderer surface (caixa-mesh per-CiliumNetworkPolicy /
Gateway / HTTPRoute construction, caixa-flux per-
GitRepository / HelmRelease / Kustomization construction,
caixa-helm per-Chart.yaml / values.yaml construction,
caixa-core::render per-skeleton construction) previously
carried inline as the three-line block
mapping.insert(serde_yaml::Value::String(<KEY>.into()), <VALUE>) — three per-call boilerplate axes (serde_yaml:: path
re-quote, Value::String(_) promotion, .into() &str → String
coercion) around a two-token semantic payload (<KEY>, <VALUE>).
Lifting collapses the boilerplate into one method call the
caller reads as intent (mapping.insert_str_key(<KEY>, <VALUE>)
— “insert this schema key with this rendered value”) rather
than five hand-spelled positional artifacts. The next renderer
to land — the per-:politicas CiliumClusterwideEnvoyConfig
emitter (MESH-COMPOSITION §III.2 #3), the app-operator’s
typed mesh.pleme.io/v1alpha1/Aplicacao CR materializer (§III.2
#5), the M4 cross-cluster fan-out’s per-cluster Service /
HTTPRoute backendRefs emission, the future caixa-otel
OpenTelemetry-Collector pipeline emitter — gets the canonical
key-scalar-promotion for free with one method call, instead of
re-inlining the three-line block.
Peer to the sibling render-side helpers on the
serde_yaml::Value-construction surface:
yaml_string_mapping (string→string mapping), label_selector
(K8s LabelSelector shape), kube_resource_skeleton (K8s
apiVersion+kind+metadata skeleton), single_field_overlay
(Option<T> → single-key overlay). Each closes a distinct axis
of the K8s-artifact-emit surface’s “same shape, written N times”
duplication; this one closes the per-key insert primitive the
other four all compose on top of.
Sourcefn insert_string<V: Into<String>>(
&mut self,
key: &str,
value: V,
) -> Option<Value>
fn insert_string<V: Into<String>>( &mut self, key: &str, value: V, ) -> Option<Value>
Insert (key, Value::String(value.into())) into self — the
string-scalar-valued-field emission shape that combines
Self::insert_str_key’s &str → Value::String key promotion
with an automatic Value::String promotion of an Into<String>
value. Returns the prior value at that key, mirroring
serde_yaml::Mapping::insert.
The canonical shape ~17 production call sites across the caixa-
side renderer surface previously carried inline as the three-
line block mapping.insert_str_key(<KEY>, serde_yaml::Value::String(<VALUE>.into() | .clone() | .to_string())) — the two-token semantic payload (<KEY>,
<VALUE>) buried under three boilerplate axes (serde_yaml::
path re-quote, Value::String(_) promotion, the
.into() | .clone() | .to_string() → String coercion).
Sites lifted:
- caixa-mesh’s
programs_for_aplicacaoper-:membrosentry (FLEET_PROGRAMS_KEY_NAME/FLEET_PROGRAMS_KEY_VERSAO/FLEET_PROGRAMS_KEY_APLICACAO); - caixa-mesh’s
cilium_network_policiesper-toPorts[]port entry (KUBE_KEY_PORT/KUBE_KEY_PROTOCOL) and per-HTTP- ruleCILIUM_KEY_PATHL7 predicate; - caixa-mesh’s
gateway_routesper-Gatewaylistener block (GATEWAY_API_KEY_NAME/crate::GATEWAY_API_KEY_HOSTNAME/GATEWAY_API_KEY_PROTOCOL) andspec.gatewayClassName; - caixa-mesh’s
gateway_routesper-HTTPRouteparentRefs[]name, per-rulematches[].path.{type,value}prefix-match, and per-rulebackendRefs[].namebackend-target; - caixa-flux’s
programs_yaml_entryper-entryname/namespaceaxes; - caixa-core
kube_resource_skeleton’sapiVersion/kindscalar heads (the two production emit sites the priorValue::String(_.to_string())inline shape sat at).
Lifting collapses the boilerplate into one method call the
caller reads as intent (mapping.insert_string(<KEY>, <VALUE>)
— “insert a string-scalar-typed field named KEY with rendered
value VALUE”) rather than four hand-spelled positional
artifacts. The next renderer to land — the per-:politicas
CiliumClusterwideEnvoyConfig emitter (whose per-policy string-
scalar axes are name / namespace / defaultAction), the
app-operator’s typed mesh.pleme.io/v1alpha1/Aplicacao CR
materializer (per-spec.selectors[] name / per-spec.gates[]
string-typed axes), the M4 cross-cluster fan-out’s per-cluster
Service.spec.ports[].name / HTTPRoute.spec.rules[].filters[]. requestHeaderModifier.set[].name string-scalar emission, the
future caixa-otel OpenTelemetry-Collector pipelines.traces. receivers[].endpoint string-scalar emission — gets the canonical
string-scalar-valued-field shape for free with one method call,
instead of re-inlining the three-token
Value::String(_.into() | .clone() | .to_string()) block.
Peer to Self::insert_str_key on the sibling any-Value axis —
the two together form the “one method call per emission axis”
primitive pair the K8s-artifact-emit surface’s “same shape,
written N times” duplication (THEORY.md §I.3.5) collapses onto.
Sourcefn insert_number<N: Into<Number>>(
&mut self,
key: &str,
value: N,
) -> Option<Value>
fn insert_number<N: Into<Number>>( &mut self, key: &str, value: N, ) -> Option<Value>
Insert (key, Value::Number(value.into())) into self — the
integer-scalar-valued-field emission shape that combines
Self::insert_str_key’s &str → Value::String key promotion
with an automatic serde_yaml::Value::Number promotion of an
Into<serde_yaml::Number> value. Returns the prior value at that
key, mirroring serde_yaml::Mapping::insert.
The canonical shape 2 production call sites across caixa-mesh
previously carried inline as the three-token block
mapping.insert_str_key(<KEY>, serde_yaml::Value::Number(<N>.into()))
— the two-token semantic payload (<KEY>, <N>) buried under
three boilerplate axes (serde_yaml:: path re-quote,
Value::Number(_) promotion, the <N>.into() typed-integer →
serde_yaml::Number coercion) around a numeric constant or
typed field the caller already carries as u16 / u32 / u64.
Sites lifted:
- caixa-mesh’s
gateway_routesper-Gatewayspec.listeners[].portexternal HTTP listener port (KUBE_KEY_PORTaround the liftedcrate::GATEWAY_API_DEFAULT_HTTP_LISTENER_PORTu16const, cd60fde); - caixa-mesh’s
gateway_routesper-HTTPRoute.spec.rules[].backendRefs[].portbackend-target Servico port (KUBE_KEY_PORTaround thecrate::AplicacaoSpec-sideentrada.portu16field the:entrada :porttyped slot flows through).
Lifting collapses the boilerplate into one method call the
caller reads as intent (mapping.insert_number(<KEY>, <N>) —
“insert a numeric-scalar-typed field named KEY with the typed
integer N”) rather than three hand-spelled positional artifacts.
The next renderer to land — the per-:politicas
CiliumClusterwideEnvoyConfig emitter (whose per-policy
integer-scalar axes are the Envoy circuit-breaker
maxRequests / maxPendingRequests / maxConnections count
fields and the Cilium ratelimit requestPerUnit field,
MESH-COMPOSITION §III.2 #3), the app-operator’s typed
mesh.pleme.io/v1alpha1/Aplicacao CR materializer (per-spec. selectors[] integer-scored weight fields, §III.2 #5), the
M4 cross-cluster fan-out’s per-cluster
Service.spec.ports[].{port, targetPort, nodePort} /
HTTPRoute.spec.rules[].backendRefs[].{port, weight}
integer-scalar emission, the future caixa-otel
OpenTelemetry-Collector service.pipelines.traces.receivers[]. grpc.max_recv_msg_size_mib integer-scalar emission — gets the
canonical integer-scalar-valued-field shape for free with one
method call, instead of re-inlining the three-token
Value::Number(_.into()) block.
The Into<serde_yaml::Number> bound accepts every numeric
primitive serde_yaml::Number declares From for
(i8..=i64, u8..=u64, f32, f64) — the same coverage
the two production sites reach through with their u16 port
fields and the same coverage every future numeric-scalar
emission (the K8s Service.spec.ports[].targetPort IntOrString
integer arm, the HTTPRoute.spec.rules[].backendRefs[].weight
int32 axis, the Envoy maxRequests uint32 axis) reaches
through with matching typed integer fields.
Peer to Self::insert_string on the sibling string-scalar axis
and to Self::insert_mapping / Self::insert_sequence on
the sibling nested-Mapping / list-shape axes — the five together
with Self::insert_str_key form the “one method call per
emission axis” primitive quintuple the K8s-artifact-emit
surface’s “same shape, written N times” duplication (THEORY.md
§I.3.5) collapses onto: insert_str_key for any-Value inserts,
insert_string for the string-scalar-valued-field shape,
insert_number for the integer-scalar-valued-field shape,
insert_mapping for the nested-Mapping-valued-field shape,
insert_sequence for the list-shape-valued-field shape.
Sourcefn insert_mapping(&mut self, key: &str, value: Mapping) -> Option<Value>
fn insert_mapping(&mut self, key: &str, value: Mapping) -> Option<Value>
Insert (key, Value::Mapping(value)) into self — the
nested-Mapping-valued-field emission shape that combines
Self::insert_str_key’s &str → Value::String key promotion
with an automatic serde_yaml::Value::Mapping promotion of a
serde_yaml::Mapping value. Returns the prior value at that
key, mirroring serde_yaml::Mapping::insert.
The canonical shape ~6 production call sites across the caixa-
side renderer surface previously carried inline as the three-
token block mapping.insert_str_key(<KEY>, serde_yaml::Value::Mapping(<INNER>)) — a two-token semantic
payload (<KEY>, <INNER>) buried under a two-axis boilerplate
(serde_yaml:: path re-quote, Value::Mapping(_) promotion)
around a Mapping variable the caller already built.
Sites lifted:
- caixa-mesh’s
cilium_network_policiesper-toPorts[]rules:L7-introspection sub-block (KUBE_KEY_RULESaround the builtrulesMapping); - caixa-mesh’s
cilium_network_policiesper-CiliumNetworkPolicyspec:block (KUBE_KEY_SPECaround the builtpolicy_specMapping); - caixa-mesh’s
gateway_routesper-Gatewayspec:block (KUBE_KEY_SPECaround the builtg_specMapping); - caixa-mesh’s
gateway_routesper-HTTPRoute.spec.rules[]matches[].path:sub-block (GATEWAY_API_KEY_PATHaround the builtpath_matchMapping); - caixa-mesh’s
gateway_routesper-HTTPRoutespec:block (KUBE_KEY_SPECaround the builtr_specMapping); - caixa-core’s
kube_resource_skeletonper-CRmetadata:sub-block (KUBE_KEY_METADATAaround the builtmetadata_mapMapping).
Lifting collapses the boilerplate into one method call the
caller reads as intent (mapping.insert_mapping(<KEY>, <INNER>)
— “insert a nested-Mapping-typed sub-block named KEY with the
built inner INNER”) rather than three hand-spelled positional
artifacts. The next renderer to land — the per-:politicas
CiliumClusterwideEnvoyConfig emitter (whose per-policy
nested-Mapping sub-blocks are metadata: / spec: /
spec.resources[]), the app-operator’s typed
mesh.pleme.io/v1alpha1/Aplicacao CR materializer
(per-spec.selectors[] and per-spec.gates[] sub-blocks), the
M4 cross-cluster fan-out’s per-cluster Service.spec /
HTTPRoute.spec sub-block emission, the future caixa-otel
OpenTelemetry-Collector per-pipeline receivers: /
processors: / exporters: nested-Mapping emission — gets the
canonical nested-Mapping-valued-field shape for free with one
method call, instead of re-inlining the three-token
Value::Mapping(_) promotion.
Peer to Self::insert_string on the sibling scalar-value axis
and Self::insert_sequence on the sibling list-shape axis —
the four together with Self::insert_str_key form the “one
method call per emission axis” primitive quadruple the K8s-
artifact-emit surface’s “same shape, written N times” duplication
(THEORY.md §I.3.5) collapses onto: insert_str_key for any-Value
inserts, insert_string for the string-scalar-valued-field
shape, insert_mapping for the nested-Mapping-valued-field
shape, insert_sequence for the list-shape-valued-field shape.
Sourcefn insert_sequence(&mut self, key: &str, value: Vec<Value>) -> Option<Value>
fn insert_sequence(&mut self, key: &str, value: Vec<Value>) -> Option<Value>
Insert (key, Value::Sequence(value)) into self — the
list-shape-valued-field emission shape that combines
Self::insert_str_key’s &str → Value::String key promotion
with an automatic serde_yaml::Value::Sequence promotion of a
pre-built Vec<serde_yaml::Value> value. Returns the prior
value at that key, mirroring serde_yaml::Mapping::insert.
The canonical shape 4 production call sites across caixa-mesh
previously carried inline as the three-token block
mapping.insert_str_key(<KEY>, serde_yaml::Value::Sequence(<VEC>))
— a two-token semantic payload (<KEY>, <VEC>) buried under a
two-axis boilerplate (serde_yaml:: path re-quote,
Value::Sequence(_) promotion) around a Vec<Value> variable
the caller already built.
Sites lifted:
- caixa-mesh’s
cilium_network_policiesper-CiliumNetworkPolicyspec.ingress[].fromEndpoints:singleton-list (CILIUM_KEY_FROM_ENDPOINTSaround avec![from_endpoint]selector wrapper); - caixa-mesh’s
cilium_network_policiesper-CiliumNetworkPolicyspec.ingress[].toPorts:list (CILIUM_KEY_TO_PORTSaround the builtto_ports_seqper-edge port-and-L7-rule vec); - caixa-mesh’s
gateway_routesper-HTTPRoutespec.hostnames:singleton-list (GATEWAY_API_KEY_HOSTNAMESaround avec![Value::String(entrada.host…)]host wrapper); - caixa-mesh’s
gateway_routesper-HTTPRoutespec.rules:list (KUBE_KEY_RULESaround the builtrulesper-path match+backend+overlay vec).
Lifting collapses the boilerplate into one method call the
caller reads as intent (mapping.insert_sequence(<KEY>, <VEC>)
— “insert a list-shape-typed sub-block named KEY with the built
inner VEC”) rather than three hand-spelled positional
artifacts. The next renderer to land — the per-:politicas
CiliumClusterwideEnvoyConfig emitter (whose per-policy
list-shape sub-blocks are spec.resources[] / spec.listeners[]
/ spec.virtualHosts[], MESH-COMPOSITION §III.2 #3), the
app-operator’s typed mesh.pleme.io/v1alpha1/Aplicacao CR
materializer (per-spec.selectors[] and per-spec.gates[]
list-shape sub-blocks, §III.2 #5), the M4 cross-cluster fan-out’s
per-cluster Service.spec.ports[] /
HTTPRoute.spec.rules[].backendRefs[] list emission, the future
caixa-otel OpenTelemetry-Collector per-pipeline receivers[]
/ processors[] / exporters[] list emission — gets the
canonical list-shape-valued-field shape for free with one method
call, instead of re-inlining the three-token Value::Sequence(_)
promotion.
Peer to Self::insert_mapping on the sibling nested-Mapping
axis and Self::insert_string on the sibling scalar-value axis
— the four together with Self::insert_str_key form the “one
method call per emission axis” primitive quadruple the K8s-
artifact-emit surface’s “same shape, written N times” duplication
(THEORY.md §I.3.5) collapses onto: insert_str_key for any-Value
inserts, insert_string for the string-scalar-valued-field
shape, insert_mapping for the nested-Mapping-valued-field
shape, insert_sequence for the list-shape-valued-field shape.
Complementary to singleton_mapping_sequence on the peer
singleton-list-shape axis: singleton_mapping_sequence(m) builds
the sole-Mapping-element Value::Sequence payload;
insert_sequence(K, v) inserts an already-built Vec<Value>
payload under a schema key. A caller composing the two through
Self::insert_singleton_mapping_sequence writes
mapping.insert_singleton_mapping_sequence(K, m) for the
singleton case (the sole element is a fresh Mapping); reach for
mapping.insert_sequence(K, v) for the multi-element or
non-Mapping-element case (the vec is built up per-iteration or
wraps a non-Mapping scalar).
Sourcefn insert_singleton_mapping_sequence(
&mut self,
key: &str,
value: Mapping,
) -> Option<Value>
fn insert_singleton_mapping_sequence( &mut self, key: &str, value: Mapping, ) -> Option<Value>
Insert (key, Value::Sequence(vec![Value::Mapping(value)])) into
self — the singleton-Mapping-list-shape-valued-field emission
shape that composes Self::insert_str_key’s
&str → Value::String key promotion with the
singleton_mapping_sequence helper’s singleton-list wrap of a
serde_yaml::Mapping payload. Returns the prior value at that
key, mirroring serde_yaml::Mapping::insert.
The canonical shape 7 production call sites across caixa-mesh
previously carried inline as the two-token composition
mapping.insert_str_key(<KEY>, singleton_mapping_sequence(<M>))
— a two-token semantic payload (<KEY>, <M>) buried under a
two-symbol boilerplate (insert_str_key(_, _) +
singleton_mapping_sequence(_)) that fully covers the axis: every
site both wraps its per-call Mapping as the sole-element list
value and inserts it under a schema key on an outer Mapping. A
rebrand on either half — the outer key-scalar promotion axis
migrating to a per-key typed Value variant, the singleton-list
wrap migrating to a Server-Side-Apply-typed Value::Tagged
per-CRD-list shape once K8s per-field ownership annotations reach
the K8s Gateway API / Cilium NetworkPolicy CRD list schemas —
would silently desynchronize one site while leaving the other six
on the old shape.
Sites lifted:
- caixa-mesh’s
cilium_network_policiesper-toPorts[]port entryports:singleton-list (CILIUM_KEY_PORTSaround the builtport_entryMapping); - caixa-mesh’s
cilium_network_policiesper-toPorts[]L7rules.http:singleton-list (CILIUM_KEY_HTTParound the builthttp_ruleMapping); - caixa-mesh’s
cilium_network_policiesper-CiliumNetworkPolicyspec.ingress:singleton-list (CILIUM_KEY_INGRESSaround the builtingress_ruleMapping); - caixa-mesh’s
gateway_routesper-Gatewayspec.listeners:singleton-list (GATEWAY_API_KEY_LISTENERSaround the builtlistenerMapping); - caixa-mesh’s
gateway_routesper-HTTPRoute.spec.rules[]matches:singleton-list (GATEWAY_API_KEY_MATCHESaround the builtmatch_entryMapping); - caixa-mesh’s
gateway_routesper-HTTPRoute.spec.rules[]backendRefs:singleton-list (GATEWAY_API_KEY_BACKEND_REFSaround the builtbackend_refMapping); - caixa-mesh’s
gateway_routesper-HTTPRoutespec.parentRefs:singleton-list (GATEWAY_API_KEY_PARENT_REFSaround the builtparent_refMapping).
Lifting collapses the two-symbol composition into one method call
the caller reads as intent (mapping.insert_singleton_mapping_sequence (<KEY>, <M>) — “insert a singleton-Mapping-list-shape sub-block
named KEY wrapping the built inner M”) rather than two
nested calls. Peer to Self::insert_sequence on the sibling
multi-element or non-Mapping-element list-shape axis — the two
together partition the list-shape-valued-field emission surface:
Self::insert_singleton_mapping_sequence for the sole-Mapping-
element case, Self::insert_sequence for every other case.
The next renderer to land — the per-:politicas
CiliumClusterwideEnvoyConfig emitter (whose singleton
spec.resources:[] / spec.listeners:[] / spec.virtualHosts:[]
Mapping-element blocks, MESH-COMPOSITION §III.2 #3, are exactly the
singleton-Mapping-list shape), the app-operator’s typed
mesh.pleme.io/v1alpha1/Aplicacao CR materializer (per-single-
selector / per-single-gate emission, §III.2 #5), the M4 cross-
cluster fan-out’s per-cluster singleton Service.spec.ports[] /
HTTPRoute.spec.rules[].backendRefs[] sole-element emission, the
future caixa-otel OpenTelemetry-Collector pipelines.traces. receivers[] singleton-receiver emission — gets the canonical
singleton-Mapping-list-shape wrap+insert for free with one method
call, instead of re-inlining the two-symbol composition.
Sourcefn entry_str_key(&mut self, key: &str) -> Entry<'_>
fn entry_str_key(&mut self, key: &str) -> Entry<'_>
Entry-API sibling of Self::insert_str_key — mint the
Value::String(<KEY>.into()) key-promotion the underlying
serde_yaml::Mapping::entry method’s Value parameter
demands, and return the entry-API’s
serde_yaml::mapping::Entry handle the caller composes
.or_insert(<V>) / .or_insert_with(<F>) /
.and_modify(<F>) / .or_default() on.
The canonical shape 4 production call sites across caixa-flux
previously carried inline as the three-token composition
mapping.entry(serde_yaml::Value::String(<KEY>.into())) around
a one-token semantic payload (the schema key axis-name). Every
site immediately composes an .or_insert(...) on the returned
serde_yaml::mapping::Entry handle — the pattern is the
entry-API twin of the Self::insert_str_key pattern the
~48 fresh-emit sites already collapsed onto (23506b3).
Sites lifted:
- caixa-flux’s
programs_yaml_entryper-servico_m2_overlaykey idempotent-upsert loop (entry.entry(Value::String( <key>.to_string())).or_insert(<value>)— one.or_insert(...)perM2_KEY_LIMITS/M2_KEY_BEHAVIOR/M2_KEY_UPGRADE_FROMaxis, iterating theservico_m2_overlayBTreeMap); - caixa-flux’s
upsert_into_helmrelease_programsper-HelmRelease.spec.valuesupsert-if-absent (FLUX_KEY_VALUESaround a default freshValue::Mapping); - caixa-flux’s
upsert_into_helmrelease_programsper-HelmRelease.spec.values.programsupsert-if-absent (FLEET_PROGRAMS_KEY_PROGRAMSaround a default freshValue::Sequence); - caixa-flux’s
upsert_into_programs_yamlper-top-levelprograms:upsert-if-absent (FLEET_PROGRAMS_KEY_PROGRAMSaround a default freshValue::Sequence— the sibling of theupsert_into_helmrelease_programssite on the same key, one path deep in a HelmReleasespec.values.sub-tree, one path at the values.yaml root).
Lifting collapses the three-token composition into one method
call the caller reads as intent
(mapping.entry_str_key(<KEY>).or_insert(<DEFAULT>) — “get the
entry handle for this schema key and default it if missing”)
rather than four hand-spelled positional artifacts
(serde_yaml:: path re-quote, Value::String(_) promotion,
the .into() | .to_string() &str → String coercion, plus the
.entry(_) call itself). The next renderer to land — the
per-:politicas CiliumClusterwideEnvoyConfig emitter (which
upserts singleton spec.resources:[] / spec.listeners:[]
blocks under an existing per-cluster overlay CR, MESH-COMPOSITION
§III.2 #3), the app-operator’s typed
mesh.pleme.io/v1alpha1/Aplicacao CR materializer (which
upserts status. sub-fields on partial reconciles, §III.2 #5),
the M4 cross-cluster fan-out’s per-cluster idempotent
HelmRelease upsert — gets the canonical entry-API key-promotion
for free with one method call, instead of re-inlining the
three-token block.
Peer to Self::insert_str_key on the sibling fresh-emit
axis of the same &str → Value::String key-promotion — the
two together partition the Mapping-write surface: entry-API
for idempotent-upsert sites where the caller cares whether the
prior value was present (or_insert / and_modify /
or_default composition), insert-API for fresh-emit sites where
the caller unconditionally writes a value and either drops or
pattern-matches on the returned Option<Value> prior value.
Sourcefn insert_str_key_if_some(
&mut self,
key: &str,
value: Option<&Value>,
) -> Option<Value>
fn insert_str_key_if_some( &mut self, key: &str, value: Option<&Value>, ) -> Option<Value>
Arity-0-or-1 twin of Self::insert_str_key — insert
(key, value.clone()) iff value is Some; leave self
untouched iff value is None. Returns the prior value at that
key when the insert fires (mirroring
serde_yaml::Mapping::insert), and None otherwise (no insert
happened, so no prior value can be surfaced).
The canonical shape 3 production call sites across caixa-mesh
previously carried inline as the three-line block
if let Some(<x>) = &<overlay> { <mapping>.insert_str_key(<KEY>, <x>.clone()); } around a two-token semantic payload (the schema
key axis-name + the Option<Value> overlay slot). Every site
pairs a per-:politicas overlay single_field_overlay Option <Value> output with the same conditional-insert conditional —
the arity-0-or-1 twin of Self::insert_str_key’s always-1
arity on the per-(:de, :para) axis.
Sites lifted:
- caixa-mesh’s
cilium_network_policiesper-ingress-rule:politicas :mtls-requiredmutual-auth overlay (crate::CILIUM_KEY_AUTHENTICATIONaround themtls_overlaysingle_field_overlayoutput — the tristate{mode: required | disabled}block or the None-omit arm); - caixa-mesh’s
gateway_routesper-HTTPRoute-rule:politicas :timeoutrequest-deadline overlay (crate::GATEWAY_API_KEY_TIMEOUTSaround thetimeout_overlaysingle_field_overlayoutput — the{request: "<duration>"}block or the None-omit arm); - caixa-mesh’s
gateway_routesper-HTTPRoute-rule:politicas :retriesretry-attempt-cap overlay (crate::GATEWAY_API_KEY_RETRYaround theretry_overlaysingle_field_overlayoutput — the{attempts: <N>}block or the None-omit arm).
Lifting collapses the three-line block into one method call the
caller reads as intent (mapping.insert_str_key_if_some(<KEY>, <overlay>.as_ref()) — “insert this schema key if the overlay
carried a value; else leave the key absent”) rather than four
hand-spelled positional artifacts (the if let Some(_) = &_
destructure, the per-inner .clone(), the trailing brace, plus
the .insert_str_key(_) call itself). The absent-overlay arm —
which every [MeshPolicy] axis defaults to when the author
leaves the typed slot unset (the None arm of the
Option<Value> single_field_overlay output) — reads as the
method’s own Option::None branch, not a per-call-site inverted
if let Some scaffold around a per-call-site clone.
The next renderer to land — the per-:politicas
CiliumClusterwideEnvoyConfig emitter (whose per-policy
authentication: / rateLimit: / circuitBreaker: Option
overlays, MESH-COMPOSITION §III.2 #3, thread through the same
single_field_overlay Option<Value> axis the three lifted
sites here already reach), the app-operator’s typed
mesh.pleme.io/v1alpha1/Aplicacao CR materializer (whose per-
selector status. sub-field overlays are the same arity-0-or-1
shape, §III.2 #5), the M4 cross-cluster fan-out’s per-cluster
HTTPRoute.spec.rules[].filters[] per-filter Option overlays
(the same shape at the per-cluster axis) — gets the canonical
arity-0-or-1 conditional-insert for free with one method call,
instead of re-inlining the three-line if let Some { clone; insert_str_key } block.
Peer to Self::insert_str_key on the always-1 arity axis
(fresh-emit sites where the caller unconditionally writes a
value) — the two together partition the fresh-emit surface
exactly on the arity axis: Self::insert_str_key for
unconditional writes, Self::insert_str_key_if_some for
conditional writes gated on an Option<Value> upstream
producer (the per-:politicas overlay
single_field_overlay axis, and every future arity-0-or-1
axis every future renderer’s optional-slot machinery reaches
through).
The Option<&Value> shape (as opposed to an owned
Option<Value>) lets the caller pass overlay.as_ref() on an
owned Option<Value> the caller reuses across iterations of an
outer per-(:de, :para) or per-rule loop — every lifted site
consumes the overlay from a loop-outer binding into each of N
per-iteration Mappings, so the clone happens iff the insert
fires (the None arm skips the clone entirely) and the outer
binding stays available for the next iteration.
Sourcefn entry_or_default_mapping(&mut self, key: &str) -> Option<&mut Mapping>
fn entry_or_default_mapping(&mut self, key: &str) -> Option<&mut Mapping>
Fetch a &mut serde_yaml::Mapping at key, defaulting an empty
serde_yaml::Mapping into place when the entry is absent.
Returns Some(&mut inner) on the absent-key (fresh empty
Mapping) and present-Mapping arms; None iff key holds a
different serde_yaml::Value variant — a structural
container-type mismatch the caller surfaces as its own
domain-specific error (Error::MissingField("spec.values must be a mapping") for the caixa-flux Flux-HelmRelease overlay
walker).
The canonical shape 1 production call site in caixa-flux
(upsert_into_helmrelease_programs’s per-HelmRelease.spec.values
container-upsert on the way down to
spec.values.programs[]) previously carried inline as a
four-line block combining Self::entry_str_key’s entry-API
key promotion (68d035e), an
.or_insert(Value::Mapping(Mapping::new())) empty-Mapping
default, and a let Value::Mapping(inner) = _ else { Err(...) }
destructure — a two-token semantic payload (the schema key +
the domain-specific type-mismatch diagnostic) buried under
three boilerplate axes (Value::Mapping(_) variant promotion,
Mapping::new() empty-container construction, the outer
let else destructure). Peer to
Self::entry_or_default_sequence on the sibling Vec<Value>-
valued idempotent-container-upsert axis — the two together
partition the entry-API-container-upsert surface exactly on the
container-variant axis: Self::entry_or_default_mapping for
nested-Mapping sub-blocks, Self::entry_or_default_sequence
for list-shape sub-blocks.
Sites lifted:
- caixa-flux’s
upsert_into_helmrelease_programsper-HelmRelease.spec.valuescontainer-upsert (FLUX_KEY_VALUESaround the default freshValue::Mapping, on the way down to the nestedspec.values.programs[]sequence).
Lifting collapses the four-line block into one method call the
caller reads as intent (mapping.entry_or_default_mapping(<KEY>) .ok_or(<ERR>)? — “give me the nested Mapping at this schema
key, defaulting empty if absent, else surface my domain
error”) rather than five hand-spelled positional artifacts
(serde_yaml:: path re-quote, Value::Mapping(_) promotion,
Mapping::new() construction, the entry-API .or_insert(...)
call, plus the outer let Value::Mapping(_) = _ else {}
destructure). The next renderer to land — the per-:politicas
CiliumClusterwideEnvoyConfig emitter (whose per-cluster
upsert walks
HelmRelease.spec.values.<library>.<:politicas-axis>,
idempotent-upserting nested-Mapping sub-blocks under each
axis, MESH-COMPOSITION §III.2 #3), the app-operator’s typed
mesh.pleme.io/v1alpha1/Aplicacao CR materializer (which
upserts status.<axis> nested-Mapping sub-blocks on partial
reconciles, §III.2 #5), the M4 cross-cluster fan-out’s
per-cluster idempotent HelmRelease.spec.values.<library>
container-upsert — gets the canonical entry-API-with-
container-type-check for free with one method call, instead
of re-inlining the four-line block.
The default-empty-Mapping construction fires only on the
absent-key arm (.or_insert_with(...) gates the closure on
vacancy) — the present-key arm reuses the existing Mapping
verbatim, so the caller’s downstream writes on &mut inner
compose with any prior overlay writes from earlier passes
(the exact idempotent-upsert semantic the caixa-flux
per-cluster feira app deploy write path depends on to
preserve operator-pinned overlays across re-renders).
Sourcefn entry_or_default_sequence(&mut self, key: &str) -> Option<&mut Vec<Value>>
fn entry_or_default_sequence(&mut self, key: &str) -> Option<&mut Vec<Value>>
Fetch a &mut Vec<serde_yaml::Value> at key, defaulting an
empty Vec<serde_yaml::Value> into place when the entry is
absent. Returns Some(&mut inner) on the absent-key (fresh
empty Sequence) and present-Sequence arms; None iff key
holds a different serde_yaml::Value variant — a structural
container-type mismatch the caller surfaces as its own
domain-specific error (Error::MissingField("programs must be a sequence") for the caixa-flux fleet-programs upsert
walkers).
The canonical shape 2 production call sites in caixa-flux
(upsert_into_helmrelease_programs’s per-
HelmRelease.spec.values.programs container-upsert and
upsert_into_programs_yaml’s top-level programs: container-
upsert) previously carried inline as a four-line block
combining Self::entry_str_key’s entry-API key promotion
(68d035e), an .or_insert(Value::Sequence(Vec::new()))
empty-Sequence default, and a match _ { Value::Sequence(seq) => seq, _ => return Err(...) } destructure — a two-token
semantic payload (the schema key + the domain-specific
type-mismatch diagnostic) buried under three boilerplate axes
(Value::Sequence(_) variant promotion, Vec::new()
empty-container construction, the outer match destructure).
Peer to Self::entry_or_default_mapping on the sibling
nested-Mapping-valued idempotent-container-upsert axis.
Sites lifted:
- caixa-flux’s
upsert_into_helmrelease_programsper-HelmRelease.spec.values.programslist-container-upsert (FLEET_PROGRAMS_KEY_PROGRAMSaround the default freshValue::Sequence, one path deep in aHelmReleasespec.values.sub-tree); - caixa-flux’s
upsert_into_programs_yamlper-top-levelprograms:list-container-upsert (FLEET_PROGRAMS_KEY_PROGRAMSaround the default freshValue::Sequence— the sibling of theupsert_into_helmrelease_programssite on the same key, one path at the values.yaml root).
Lifting collapses the four-line block into one method call the
caller reads as intent (mapping.entry_or_default_sequence(<KEY>) .ok_or(<ERR>)? — “give me the list at this schema key,
defaulting empty if absent, else surface my domain error”)
rather than five hand-spelled positional artifacts
(serde_yaml:: path re-quote, Value::Sequence(_) promotion,
Vec::new() construction, the entry-API .or_insert(...)
call, plus the outer match { Value::Sequence(_) => _, _ => return Err(_) } destructure). The next renderer to land — the
per-:politicas CiliumClusterwideEnvoyConfig emitter
(whose per-cluster upsert walks nested list-shape sub-blocks
spec.resources[] / spec.listeners[] / spec.virtualHosts[]
under existing operator-pinned overlay CRs, MESH-COMPOSITION
§III.2 #3), the app-operator’s typed
mesh.pleme.io/v1alpha1/Aplicacao CR materializer (which
upserts status.selectors[] / status.gates[] list-shape
sub-blocks on partial reconciles, §III.2 #5), the M4 cross-
cluster fan-out’s per-cluster idempotent
HelmRelease.spec.values.programs list-upsert — gets the
canonical entry-API-with-container-type-check for free with
one method call, instead of re-inlining the four-line block.
The default-empty-Sequence construction fires only on the
absent-key arm (.or_insert_with(...) gates the closure on
vacancy) — the present-key arm reuses the existing Vec
verbatim, so the caller’s downstream upsert_named_entry
(10bf310) call on &mut inner composes with any prior
entries the emitter wrote on earlier passes (the exact
idempotent-upsert semantic the feira app deploy per-cluster
write path depends on to preserve prior programs[] entries
across per-Servico rewrites).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".