1 #![allow(dead_code)]
2
3 #[cfg(feature = "use_core")]
4 extern crate core;
5
6 #[macro_use]
7 extern crate derivative;
8
9 use std::marker::PhantomData;
10
11 #[derive(Derivative)]
12 #[derivative(Debug)]
13 struct Foo<T, U> {
14 foo: T,
15 #[derivative(Debug="ignore")]
16 bar: U,
17 }
18
19 #[derive(Derivative)]
20 #[derivative(Debug)]
21 struct Bar<T, U> (
22 T,
23 #[derivative(Debug="ignore")]
24 U,
25 );
26
27 #[derive(Derivative)]
28 #[derivative(Debug)]
29 enum C<T, U> {
30 V1(T),
31 V2(#[derivative(Debug="ignore")] U),
32 V3(String),
33 }
34
35 #[derive(Derivative)]
36 #[derivative(Debug)]
37 enum D<U> {
38 V1 {
39 #[derivative(Debug="ignore")]
40 a: U
41 }
42 }
43
44 #[derive(Derivative)]
45 #[derivative(Debug)]
46 struct F<U>(#[derivative(Debug="ignore")] U);
47
48 #[derive(Derivative)]
49 #[derivative(Debug)]
50 struct G<U>(isize, #[derivative(Debug="ignore")] U);
51
52 #[derive(Derivative)]
53 #[derivative(Debug)]
54 struct J<U>(#[derivative(Debug="ignore")] U);
55
56 struct NoDebug;
57
58 trait ToDebug {
to_show(&self) -> String59 fn to_show(&self) -> String;
60 }
61
62 impl<T: std::fmt::Debug> ToDebug for T {
to_show(&self) -> String63 fn to_show(&self) -> String {
64 format!("{:?}", self)
65 }
66 }
67
68 #[derive(Derivative)]
69 #[derivative(Debug)]
70 struct PhantomField<T> {
71 foo: PhantomData<T>,
72 }
73
74 #[derive(Derivative)]
75 #[derivative(Debug)]
76 struct PhantomTuple<T> {
77 foo: PhantomData<(T,)>,
78 }
79
80 #[test]
main()81 fn main() {
82 assert_eq!(Foo { foo: 42, bar: NoDebug }.to_show(), "Foo { foo: 42 }".to_string());
83 assert_eq!(Bar(42, NoDebug).to_show(), "Bar(42)".to_string());
84 assert_eq!(C::V1::<i32, NoDebug>(12).to_show(), "V1(12)".to_string());
85 assert_eq!(C::V2::<i32, NoDebug>(NoDebug).to_show(), "V2".to_string());
86 assert_eq!(C::V3::<i32, NoDebug>("foo".to_string()).to_show(), "V3(\"foo\")".to_string());
87 assert_eq!(D::V1 { a: NoDebug }.to_show(), "V1".to_string());
88 assert_eq!(F(NoDebug).to_show(), "F".to_string());
89 assert_eq!(G(42, NoDebug).to_show(), "G(42)".to_string());
90 assert_eq!(J(NoDebug).to_show(), "J".to_string());
91 assert_eq!(&format!("{:?}", PhantomField::<NoDebug> { foo: Default::default() }), "PhantomField { foo: PhantomData }");
92 assert_eq!(&format!("{:?}", PhantomTuple::<NoDebug> { foo: Default::default() }), "PhantomTuple { foo: PhantomData }");
93 }
94