4 releases (2 breaking)

0.2.0 Mar 4, 2021
0.1.1 Nov 4, 2020
0.1.0 Oct 30, 2020
0.0.1 Oct 28, 2020

#17 in #non

Download history 27/week @ 2023-12-13 19/week @ 2023-12-20 8/week @ 2023-12-27 8/week @ 2024-01-03 23/week @ 2024-01-10 9/week @ 2024-01-17 1/week @ 2024-01-24 3/week @ 2024-01-31 11/week @ 2024-02-07 28/week @ 2024-02-14 41/week @ 2024-02-21 35/week @ 2024-02-28 27/week @ 2024-03-06 30/week @ 2024-03-13 45/week @ 2024-03-20 38/week @ 2024-03-27

144 downloads per month
Used in 6 crates (via partialdebug)

MIT/Apache

13KB
299 lines

partialdebug

github Crates.io docs.rs

Derive Debug for types where not all fields implement Debug.

This crate works on stable and with no_std. On nightly the unstable feature can be used for specialization based trait detection and/or .. formatting.

Placeholder with Type Info

use partialdebug::placeholder::PartialDebug;

#[derive(PartialDebug)]
struct Dog {
    legs: usize,
    eyes: usize,
    dna: DNA,
}

assert_eq!(format!("{:?}", Dog::new()), "Dog { legs: 4, eyes: 2, dna: DNA }");

Placeholder with Custom Text

use partialdebug::placeholder::PartialDebug;

#[derive(PartialDebug)]
#[debug_placeholder = "Unknown"]
struct Dog {
    legs: usize,
    eyes: usize,
    dna: DNA,
}

assert_eq!(format!("{:?}", Dog::new()), "Dog { legs: 4, eyes: 2, dna: Unknown }");

Non Exhaustive

Only available on nightly after setting the unstable feature.

Requires the debug_non_exhaustive feature to be enabled in user code.

Only available for structs with named fields.

#![feature(debug_non_exhaustive)]
use partialdebug::non_exhaustive::PartialDebug;

#[derive(PartialDebug)]
struct Dog {
    legs: usize,
    eyes: usize,
    dna: DNA,
}

assert_eq!(format!("{:?}", Dog::new()), "Dog { legs: 4, eyes: 2, .. }");

Caveats

Trait detection for generic types requires specialization. To enable specialization based trait detection use a nightly compiler and enable the unstable feature.

use partialdebug::placeholder::PartialDebug;

#[derive(PartialDebug)]
struct Container<T>(T);

#[cfg(feature = "unstable")]
assert_eq!(format!("{:?}", Container(42)), "Container(42)");
#[cfg(not(feature = "unstable"))]
assert_eq!(format!("{:?}", Container(42)), "Container(T)");

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~1.5MB
~34K SLoC