1+ //! Derive Debug for types where not all fields implement Debug
2+ //!
13//! # Non Exhaustive
24//!
35//! ```
46//! #![feature(debug_non_exhaustive)]
57//! use partialdebug::non_exhaustive::PartialDebug;
68//!
7- //! # #[allow(dead_code)]
8- //! # struct DNA {
9- //! # sequence: &'static str,
10- //! # }
9+ //! # struct DNA;
1110//! #
1211//! #[derive(PartialDebug)]
1312//! struct Dog {
2120//! # Dog {
2221//! # legs: 4,
2322//! # eyes: 2,
24- //! # dna: DNA {
25- //! # sequence: "",
26- //! # },
23+ //! # dna: DNA,
2724//! # }
2825//! # }
2926//! # }
3633//! ```
3734//! use partialdebug::placeholder::PartialDebug;
3835//!
39- //! # #[allow(dead_code)]
40- //! # struct DNA {
41- //! # sequence: &'static str,
42- //! # }
36+ //! # struct DNA;
4337//! #
4438//! #[derive(PartialDebug)]
4539//! struct Dog {
5347//! # Dog {
5448//! # legs: 4,
5549//! # eyes: 2,
56- //! # dna: DNA {
57- //! # sequence: "",
58- //! # },
50+ //! # dna: DNA,
5951//! # }
6052//! # }
6153//! # }
6860//! ```
6961//! use partialdebug::placeholder::PartialDebug;
7062//!
71- //! # #[allow(dead_code)]
72- //! # struct DNA {
73- //! # sequence: &'static str,
74- //! # }
63+ //! # struct DNA;
7564//! #
7665//! #[derive(PartialDebug)]
7766//! #[debug_placeholder = "Unknown"]
8675//! # Dog {
8776//! # legs: 4,
8877//! # eyes: 2,
89- //! # dna: DNA {
90- //! # sequence: "",
91- //! # },
78+ //! # dna: DNA,
9279//! # }
9380//! # }
9481//! # }
9885
9986#![ allow( incomplete_features) ]
10087#![ feature( specialization) ]
88+ #![ warn( missing_docs, trivial_casts, rust_2018_idioms) ]
10189
10290use core:: fmt:: { Debug , Formatter , Result } ;
10391
92+ /// Specialized trait used to distinguish between types that implement Debug and one's that don't^.
93+ /// ```
94+ /// # use partialdebug::AsDebug;
95+ /// # struct DNA;
96+ /// # let dna = DNA;
97+ /// assert!(42.as_debug().is_some());
98+ /// assert!(dna.as_debug().is_none());
99+ /// ```
104100pub trait AsDebug {
101+ /// Try to get a reference to `self` as `dyn Debug`
105102 fn as_debug ( & self ) -> Option < & dyn Debug > ;
106103}
107104
@@ -117,6 +114,11 @@ impl<T: Debug> AsDebug for T {
117114 }
118115}
119116
117+ /// Placeholder struct for types that do not implement Debug
118+ /// ```
119+ /// # use partialdebug::Placeholder;
120+ /// assert_eq!(format!("{:?}", Placeholder("Foo")), "Foo")
121+ /// ```
120122pub struct Placeholder ( pub & ' static str ) ;
121123
122124impl Debug for Placeholder {
@@ -125,10 +127,12 @@ impl Debug for Placeholder {
125127 }
126128}
127129
130+ /// The non exhaustive version of `PartialDebug`
128131pub mod non_exhaustive {
129132 pub use partialdebug_derive:: NonExhaustivePartialDebug as PartialDebug ;
130133}
131134
135+ /// The placeholder version of `PartialDebug`
132136pub mod placeholder {
133137 pub use partialdebug_derive:: PlaceholderPartialDebug as PartialDebug ;
134138}
0 commit comments