Skip to main content

guard_bare_overwrite

Function guard_bare_overwrite 

Source
pub fn guard_bare_overwrite(existing: Option<&Value>) -> Result<(), ScalarKind>
Expand description

The §3 “异型覆盖守卫” (heterogeneous-overwrite guard, closing design rule 4 — “no silent type rewrites”): a bare VALUE (implicit --value-type string) is always a string, so overwriting an existing scalar of a different kind would silently change its type. That is an argument error, not a coercion decision. Returns the existing kind so the caller can build a message with the two escape hatches (--value-type <kind> to keep the type, or --value-type string to convert explicitly).

Ok(()) when there is nothing to guard: the target is absent (a new key), already a string (no type change), or a container (out of this guard’s scope). Never called when --value-type was passed explicitly — an explicit type is a deliberate declaration, not a silent rewrite.