Crates.io | partialdebug |
lib.rs | partialdebug |
version | 0.2.0 |
source | src |
created_at | 2020-10-28 15:37:39.394059 |
updated_at | 2021-03-04 01:53:22.544488 |
description | Derive Debug partially |
homepage | |
repository | https://github.com/dimpolo/partialdebug/ |
max_upload_size | |
id | 306384 |
size | 26,065 |
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.
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 }");
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 }");
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, .. }");
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)");