pub fn coerce_toward(
raw: &str,
existing: Option<&Value>,
) -> DocumentResult<Value>Expand description
Coerce a CLI string toward the type already present at existing, for a
consumer that knows the target type from the value it is replacing (a
config setter reading typed leaves out of a serialized document).
This is the library counterpart to the CLI’s explicit --value-type: the
generic afdata CLI must ask the user for the type because it cannot know
it, but a consumer that does — because it holds the existing typed leaf, or
its own schema — should neither add a flag nor re-parse. It is type
directed, not shape guessing: the existing leaf’s scalar_kind selects
the parse; a bool/number literal that does not match falls back to a
string; a string, null, or absent leaf yields a string; a container leaf
is replaced with a JSON literal.