#custom #debug #debugging #derive #field #format

custom_debug

Derive Debug with a custom format per field

3 releases (breaking)

0.5.0 Jun 12, 2020
0.4.0 Feb 1, 2020
0.3.0 Feb 1, 2020
Download history 1727/week @ 2021-09-26 1990/week @ 2021-10-03 2559/week @ 2021-10-10 2371/week @ 2021-10-17 2238/week @ 2021-10-24 2223/week @ 2021-10-31 2029/week @ 2021-11-07 1744/week @ 2021-11-14 1561/week @ 2021-11-21 1788/week @ 2021-11-28 1907/week @ 2021-12-05 2247/week @ 2021-12-12 1257/week @ 2021-12-19 552/week @ 2021-12-26 2244/week @ 2022-01-02 2095/week @ 2022-01-09

6,178 downloads per month
Used in 7 crates (5 directly)

Apache-2.0 OR MIT

4KB
59 lines

custom_debug

Derive Debug with a custom format per field.

Usage

Here is a showcase of all possible field attributes:

    use custom_debug::Debug;
    use std::fmt;

    #[deriveDebug)]
    struct Foo {
        #[debug(format = "{} things")]
        x: i32,
        #[debug(skip)]
        y: i32,
        #[debug(with = "hex_fmt")]
        z: i32,
    }

    fn hex_fmt<T: fmt::Debug>(n: &T, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "0x{:02X?}", n)
    }

The resulting debug output would look something like this:

Foo {
    x: 42 things,
    z: 0xAB
}

Dependencies

~370–790KB
~18K SLoC

^