#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

#2757 in Rust patterns

Download history 236/week @ 2023-12-22 202/week @ 2023-12-29 322/week @ 2024-01-05 192/week @ 2024-01-12 111/week @ 2024-01-19 36/week @ 2024-01-26 29/week @ 2024-02-02 47/week @ 2024-02-09 58/week @ 2024-02-16 67/week @ 2024-02-23 194/week @ 2024-03-01 63/week @ 2024-03-08 54/week @ 2024-03-15 38/week @ 2024-03-22 54/week @ 2024-03-29 31/week @ 2024-04-05

182 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

~0.4–0.9MB
~21K SLoC