Function debug2::pprint

source · []
pub fn pprint<T: Debug>(x: T) -> String
Expand description

Pretty Print an item to a string

use debug2::pprint;

let x: Vec<Option<&[i32]>> = vec![Some(&[1; 20]), None, None, Some(&[1, 2, 3])];

assert_eq!(
    pprint(x),
    "\
[
    Some([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]),
    None,
    None,
    Some([1, 2, 3]),
]"
);

Note that while this takes a T, you can also pass a reference due to the impl<T: Debug> Debug for &T`

Panics

This will panic if <T as Debug>::fmt returns an error