1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use super::super::*;
use std::fmt::{self, Debug};

/// skip formatting the field when the value is empty or false
macro_rules! skip_fmt {
    ($base:ident, $self:ident . $($field:ident)+ ) => {$(
        if !$self.$field.is_empty() {
            $base.field(::std::stringify!($field), &$self.$field);
        }
    )+};
    (bool: $base:ident, $self:ident . $($field:ident)+ ) => {$(
        if $self.$field {
            $base.field(::std::stringify!($field), &$self.$field);
        }
    )+};
    (option: $base:ident, $self:ident . $($field:ident)+ ) => {$(
        if $self.$field.is_some() {
            $base.field(::std::stringify!($field), &$self.$field);
        }
    )+};
    (0: $base:ident, $self:ident . $($field:ident)+ ) => {$(
        if $self.$field != 0 {
            $base.field(::std::stringify!($field), &$self.$field);
        }
    )+};
}

impl Debug for DModule {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut base = f.debug_struct("DModule");
        base.field("id", &self.id);
        skip_fmt!(
            base, self . modules structs unions enums
            functions traits constants statics type_alias
            macros_decl macros_func macros_attr macros_derv
        );
        base.finish()
    }
}

impl Debug for DImpl {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut base = f.debug_struct("DImpl");
        skip_fmt!(base, self . inherent trait_ auto blanket);
        base.finish()
    }
}

impl Debug for DStruct {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut base = f.debug_struct("DStruct");
        base.field("id", &self.id);
        skip_fmt!(bool: base, self.contain_private_fields);
        skip_fmt!(base, self . fields impls);
        base.finish()
    }
}

impl Debug for DUnion {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut base = f.debug_struct("DUnion");
        base.field("id", &self.id);
        skip_fmt!(
            base, self . fields impls
        );
        base.finish()
    }
}

impl Debug for DEnum {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut base = f.debug_struct("DEnum");
        base.field("id", &self.id);
        skip_fmt!(base, self . variants impls);
        base.finish()
    }
}

impl Debug for DTrait {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut base = f.debug_struct("DTrait");
        base.field("id", &self.id);
        skip_fmt!(base, self . types constants functions implementations);
        base.finish()
    }
}

impl Debug for ItemCount {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut base = f.debug_struct("ItemCount");
        skip_fmt!(
            0: base, self . modules structs unions enums functions
            traits constants statics type_alias
            macros_decl macros_func macros_attr macros_derv
        );
        base.finish()
    }
}

impl Debug for ImplCount {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut base = f.debug_struct("ImplCount");
        if self.total != 0 {
            base.field("kind", &self.kind);
            base.field("total", &self.total);
            skip_fmt!(0: base, self . structs enums unions);
        }
        base.finish()
    }
}

impl Debug for ImplCounts {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let mut base = f.debug_struct("ImplCounts");
        if self.total.total != 0 {
            base.field("total", &self.total);
            if self.inherent.total != 0 {
                base.field("inherent", &self.inherent);
            }
            if self.trait_.total != 0 {
                base.field("trait", &self.trait_);
            }
        }
        base.finish()
    }
}