Debug

Trait Debug 

Source
pub trait Debug {
    // Required method
    fn fmt(&self, f: &mut Formatter<'_>) -> Result;
}
Expand description

Pretty Printed Formatting

This is much like std::fmt::Debug, but it supports much better multiline output

§Examples

use debug2::{pprint, Debug};

#[derive(Debug)]
struct Numbers {
    a: Vec<Vec<i32>>,
    b: String,
}

let a = Numbers {
    a: vec![vec![10; 10]; 2],
    b: "FooBar".to_owned(),
};

assert_eq!(
    pprint(&a),
    "\
Numbers {
    a: [
        [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
        [10, 10, 10, 10, 10, 10, 10, 10, 10, 10],
    ],
    b: \"FooBar\",
}"
);

You can also implement fmt manually, using an API much like std::fmt::Formatter

use debug2::{pprint, Debug, Formatter};
use std::fmt;

struct Chunked10([u8; 100]);

impl Debug for Chunked10 {
    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
        f.debug_list().entries(self.0.chunks(10)).finish()
    }
}

assert_eq!(
    pprint(Chunked10([0; 100])),
    "\
[
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
]"
);

Required Methods§

Source

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.

Note that this may be called more than once for any invocation of pprint, if you do side effects in this, make sure they are idempotent. In general, don’t relly on how often this function is called, as it may change in a future release.

Implementations on Foreign Types§

Source§

impl Debug for &str

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for bool

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for f32

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for f64

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for i8

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for i16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for i32

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for i64

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for i128

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for isize

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for u8

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for u16

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for u32

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for u64

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for u128

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for ()

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for usize

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl Debug for String

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<K, V, S> Debug for HashMap<K, V, S>
where K: Debug, V: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<K: Debug, V: Debug> Debug for BTreeMap<K, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T0: Debug, T1: Debug, T2: Debug, T3: Debug, T4: Debug, T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11> Debug for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T1: Debug, T2: Debug, T3: Debug, T4: Debug, T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11> Debug for (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T2: Debug, T3: Debug, T4: Debug, T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11> Debug for (T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T3: Debug, T4: Debug, T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11> Debug for (T3, T4, T5, T6, T7, T8, T9, T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T4: Debug, T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11> Debug for (T4, T5, T6, T7, T8, T9, T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T5: Debug, T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11> Debug for (T5, T6, T7, T8, T9, T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T6: Debug, T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11> Debug for (T6, T7, T8, T9, T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T7: Debug, T8: Debug, T9: Debug, T10: Debug, T11> Debug for (T7, T8, T9, T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T8: Debug, T9: Debug, T10: Debug, T11> Debug for (T8, T9, T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T9: Debug, T10: Debug, T11> Debug for (T9, T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T10: Debug, T11> Debug for (T10, T11)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T11> Debug for (T11,)
where T11: ?Sized + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T> Debug for BTreeSet<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T, S> Debug for HashSet<T, S>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: Copy + Debug> Debug for Cell<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: Debug> Debug for Option<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: Debug> Debug for [T]

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: Debug> Debug for BinaryHeap<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: Debug> Debug for LinkedList<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: Debug> Debug for VecDeque<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: Debug> Debug for Vec<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: Debug, const N: usize> Debug for [T; N]

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized + Debug> Debug for &T

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized + Debug> Debug for &mut T

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized + Debug> Debug for Box<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized + Debug> Debug for Rc<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized + Debug> Debug for Arc<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized + Debug> Debug for Ref<'_, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized + Debug> Debug for RefCell<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized + Debug> Debug for RefMut<'_, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized> Debug for *const T

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized> Debug for *mut T

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized> Debug for UnsafeCell<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Source§

impl<T: ?Sized> Debug for PhantomData<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Implementors§