#derive-debug #debugging #extra #derive #customisable

macro derive-debug-extras

More customisable #[derive(Debug)]

5 unstable releases

0.3.0 Mar 1, 2024
0.2.2 Jan 27, 2023
0.2.1 Jan 24, 2023
0.2.0 Dec 19, 2021
0.1.0 Nov 29, 2021

#10 in #extra

Download history 7/week @ 2024-07-21 70/week @ 2024-07-28 84/week @ 2024-08-04 62/week @ 2024-08-11 21/week @ 2024-08-18 51/week @ 2024-08-25 81/week @ 2024-09-01 13/week @ 2024-09-08 5/week @ 2024-09-15 33/week @ 2024-09-22 17/week @ 2024-09-29 25/week @ 2024-10-06 94/week @ 2024-10-13 5/week @ 2024-10-20 7/week @ 2024-10-27 23/week @ 2024-11-03

132 downloads per month
Used in 4 crates (2 directly)

MIT license

10KB
140 lines

Derive debug extras

crates.io badge docs.rs badge

More customisable #[derive(Debug)]

Adds three options:

#[debug_single_tuple_inline]

use derive_debug_extras::DebugExtras;

#[derive(DebugExtras)]
#[debug_single_tuple_inline]
struct A(pub u32);

Verbose debugging on A retains single line under verbose.

e.g. for println!("{:#?}", vec![A(123), A(145), A(125),])

// Without #[debug_single_tuple_inline]
[
    A(
        123
    ),
    A(
        145
    ),
    A(
        125
    ),
]
// With #[debug_single_tuple_inline]
[
    A(123),
    A(145),
    A(125),
]

#[debug_single_tuple_inline] works on enums as well. Will fail for unnamed tuples with more than one field or named fields.

For setting this as the default for verbose formatting for structures with one field that use #[derive(DebugExtras)], you can use the auto-debug-single-tuple-inline feature to prevent having to write #[debug_single_tuple_inline] on every structure

#[debug_ignore]

#[derive(DebugExtras)]
struct C {
    x: u32,
    #[debug_ignore]
    _y: bool,
}

Ignores the _y field when debugging

#[debug_as_display]

#[derive(DebugExtras)]
struct D {
    #[debug_as_display]
    x: String,
}

Prints the x field out as if it was formatted with Display

e.g. for println!("{:#?}", D("Hello World".to_string()))

// With #[debug_as_display]
D(Hello World)
// Without #[debug_as_display]
D("Hello World")

Dependencies

~285–720KB
~17K SLoC