Pretty-printing is great at enhancing the readability of debug output, but expanding too much can also make it hard to read.
Consider the case where I want to pretty-print an array of ordered pairs, Vec<(usize, usize)>
. In this case, each entry will take 4 lines of output -
[
(
19,
-3,
),
(
13,
-2,
),
(
15,
-2,
),
(
17,
-2,
),
(
19,
-2,
),
...
]
- when printing each entry on a single line would be sufficient for readability -
[
(19, -3),
(13, -2),
(15, -2),
(17, -2),
(19, -2),
...
]
- and arguably more readable, especially for bigger lists.
What I propose to fix this is allowing the user to specify a maximum pretty-printing depth in the format string. For a max depth of n
, only the n
-topmost-level compound types will be expanded. In this case, the desired output can be achieved by setting a maximum depth of 1.