derive-debug-extras

Crates.ioderive-debug-extras
lib.rsderive-debug-extras
version0.3.0
sourcesrc
created_at2021-11-29 12:39:08.250642
updated_at2024-03-01 10:05:13.28515
descriptionMore customisable #[derive(Debug)]
homepage
repositoryhttps://github.com/kaleidawave/derive-debug-extras
max_upload_size
id489231
size14,148
Ben (kaleidawave)

documentation

README

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")
Commit count: 8

cargo fmt