Pretty Struct
Displays (json) structures and enums in a pretty way.
This crate is linked to the crud library. If I have time and motivation to generalize it, it can be an indenpendant crate.
Example
use PrettyPrint;
// Instanciate a `var` of type `Foo`
println!;
Field Options
is_pretty
the nested struct implements PrettyPrint
and should be printed using it.
use PrettyPrint;
label
custom label for this field
color
custom color for the value of this field. The avaiable colors are [Color].
label_color
custom color for the label of dthis field. The avaiable colors are [Color].
skip
skip the field. It won't be display.
skip_none
skip the field if the value is None
. The type of the field should be an Option<T>
.
profile
the field is displayed only when this field profiles matched the profile declare when calling the pretty
function.
let foo = Foo;
foo.pretty.unwrap; // print only `field2`
formatter
Custom value formatter for this field.
Some [formatters] are shipped in this crate.
Formatters should follow this signature:
type Formatter = dyn Fn ;
Parameters:
value
: the value to formatcolored
: whentrue
the formatted value can be colored
Result:
- String: the formatted value
- bool: returns
true
if the value have colors. returnsfalse
if the value don't have colors then default color will be applied.
Enum Option
Limitations on enums:
- unit variants are supported
- tuple variants with only 1 argument are supported
color
custom color for this variant avaiable colors are [Color].
label
custom label for this variant