Skip to main content

print_rows

Function print_rows 

Source
pub fn print_rows<T>(
    rows: &[T],
    json: bool,
    to_json: impl Fn(&T) -> Value,
    to_line: impl Fn(&T) -> String,
)
Expand description

Prints a listing the way every --json-capable list command prints one: one JSON array, or one human-readable line per row.

Six commands had written out the same if json { … map(to_json).collect() … } else { for row in rows { println!(to_line) } }. The shape is the contract — a JSON listing is an array, never a stream of objects, so a caller can pipe it into jq — and it should exist once.

Takes no Palette: the to_line closure captures one at the call site, which is also what keeps the json branch structurally unable to reach it.