Skip to main content

kube_spec_seq_first_str

Function kube_spec_seq_first_str 

Source
pub fn kube_spec_seq_first_str<'a>(
    value: &'a Value,
    seq_field: &str,
    scalar_field: &str,
) -> Option<&'a str>
Expand description

Read a scalar-string leaf nested one hop below the first entry of a sub-spec.<seq_field>[] YAML sequence on a K8s custom resource YAML document as Option<&str> — the composed scalar-str-arity per- spec.<F>[0].<G> accessor peer that stands on the composed kube_spec_seq_first (b7babfe) sub-spec.<F>[] head-selector and folds the trailing .and_then(|v| kube_str(v, <G>)) scalar readback closure into one helper call the caller reads as intent (kube_spec_seq_first_str(<value>, <SEQ>, <SCALAR>) — “read the scalar <SCALAR>: string leaf on the first entry of spec.<SEQ>[]”) rather than as a two-line kube_spec_seq_first(<value>, <SEQ>).and_then(|v| kube_str(v, <SCALAR>)) navigation chain.

Structural mirror of the sibling kube_spec_str_field (c4fe21d) one altitude up on the direct sub-spec.<field> axis — where the sibling closes the string-scalar readback on the two-hop spec → as_mapping → get(<field>) → as_str walk, this closes the same string-scalar readback on the four-hop spec → as_mapping → get(<seq_field>) → as_sequence → first → get(<scalar_field>) → as_str walk one altitude deeper on the nested- first-entry axis. Peer of the composed head-selector siblings kube_spec_seq_first (b7babfe) at the raw-&Value first-entry arity, kube_spec_seq_first_seq_first (2ee7fc9) at the nested double-first arity, and kube_spec_seq_first_seq_first_seq_first (3ffa061) at the triple-first arity: the four together close the composed head-selector family on both the raw-value and the string- scalar tail arities the every routed spec.<seq>[0].<scalar> per- entry-scalar readback (the per-Gateway spec.listeners[0].hostname / spec.listeners[0].name / spec.listeners[0].protocol scalar readbacks, the per-HTTPRoute spec.parentRefs[0].name / spec.parentRefs[0].sectionName scalar readbacks, MESH-COMPOSITION §III.2) walks through — the raw-value hop via the sibling head- selector, the trailing string-scalar hop via this accessor.

Returns None on any of the six short-circuit arms folded through the underlying composition: the five outer arms (kube_spec_seq_first’s missing top-level spec: sub-block / non-mapping spec: axis / missing <seq_field> sub-field on spec: / non-sequence <seq_field> sub-field / present-but-empty <seq_field>[] sequence), plus the trailing kube_str arm’s composite short-circuits (missing <scalar_field> sub-field on the first outer entry / non-string <scalar_field> sub-field — the serde_yaml::Value::get scalar-arm short-circuit does not reach the trailing leg because the outer kube_spec_seq_first hop only yields a &Value that came out of a Mapping position on the outer sequence). The returned &str borrows into the input Value — the caller decides whether to compare (==), clone (.to_string()), unwrap-then-panic (.expect(...)), or route a fallback (.unwrap_or(...)).

The canonical shape 5 test-side per-spec.<seq_field>[0]. <scalar_field> string-scalar readback sites in caixa-mesh previously carried inline as the two-line composition

kube_spec_seq_first(<value>, <SEQ>)
    .and_then(|v| kube_str(v, <SCALAR>))
    ...

(or, on three call sites, the two-statement bound-then-scalar form let x = kube_spec_seq_first(v, SEQ).expect(...); kube_str(x, SCALAR)) across the two canonical composed axes (GATEWAY_API_KEY_LISTENERS + GATEWAY_API_KEY_HOSTNAME / GATEWAY_API_KEY_NAME on the per-Gateway first-listener scalar readbacks, GATEWAY_API_KEY_PARENT_REFS + GATEWAY_API_KEY_NAME / GATEWAY_API_KEY_SECTION_NAME on the per-HTTPRoute first- parentRef scalar readbacks). After this lift every routed consumer folds the two-line composition onto kube_spec_seq_first_str(<value>, <SEQ>, <SCALAR>) — the head-selector and the trailing scalar readback both happen once inside the helper, and the caller keeps its downstream idiom (.expect(...), .unwrap_or_else(...), == Some(<VALUE>), assert_eq!(.., Some(<VALUE>))) unchanged — the lift closes the composed navigation surface, not the per-site error- handling posture.

Every future per-spec.<seq>[0].<scalar> string-scalar readback (the future per-:politicas CiliumClusterwideEnvoyConfig per-policy spec.rules[0].name navigation MESH-COMPOSITION §III.2 #3 admits, the app-operator’s per-Aplicacao mesh.pleme.io/v1alpha1/Aplicacao CR materializer’s per-spec.<axis>[0].<sub> first-entry-scalar navigation §III.2 #5, every future test-side spec.<seq>[0].<scalar> string-scalar probe the M3.x + M4 renderer set adds) reaches this same helper by construction — no per-consumer two-line composition re-inline, no coordinated rewrite across every nested-first-entry string-scalar readback on a future serde_yaml surface rebrand or a shift in either constituent primitive’s head-selector or shape- gate semantics.