Skip to main content

value_to_text_sink

Function value_to_text_sink 

Source
pub fn value_to_text_sink(value: &Value) -> EvalResult<String>
Expand description

Materialize a Value for a TEXT SINK — string interpolation ("x=$b") or an external-command argv element (prog $b) — going LOUD on binary rather than emitting the [binary: N bytes] placeholder that value_to_string uses.

Splicing binary into text as a placeholder is silent data corruption: a command may already have captured the user’s real bytes (e.g. b=$(cat blob) stores a Value::Bytescat emits raw bytes for non-UTF-8 content), and the placeholder throws those bytes away where the data should be. Valid-UTF-8 bytes coerce (mirroring ExecResult::try_text_out); everything else is a loud error. In practice Value::Bytes only ever holds non-UTF-8 content (the producer coercion in ExecResult::success_text_or_bytes keeps valid UTF-8 as text), so this errors whenever a Bytes value reaches a text sink. See docs/binary-data.md.

This is deliberately NOT a global replacement for value_to_string — the infallible form stays correct for semantic/internal uses where a stable placeholder is wanted and no data crosses a text boundary.