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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
use rustdoc_json_types::{Item, ItemEnum, ItemKind, ItemSummary};
/// A univeral way to represent an [`ItemEnum`] or [`ItemKind`]
#[derive(Debug)]
pub(crate) enum Kind {
Module,
ExternCrate,
Import,
Struct,
StructField,
Union,
Enum,
Variant,
Function,
Typedef,
OpaqueTy,
Constant,
Trait,
TraitAlias,
Method,
Impl,
Static,
ForeignType,
Macro,
ProcAttribute,
ProcDerive,
AssocConst,
AssocType,
Primitive,
Keyword,
// Not in ItemKind
ProcMacro,
}
impl Kind {
pub fn can_appear_in_mod(self) -> bool {
use Kind::*;
match self {
Module => true,
ExternCrate => true,
Import => true,
Union => true,
Struct => true,
Enum => true,
Function => true,
Trait => true,
TraitAlias => true,
Impl => true,
Typedef => true,
Constant => true,
Static => true,
Macro => true,
ProcMacro => true,
Primitive => true,
ForeignType => true,
// FIXME(adotinthevoid): I'm not sure if these are corrent
Keyword => false,
OpaqueTy => false,
ProcAttribute => false,
ProcDerive => false,
// Only in traits
AssocConst => false,
AssocType => false,
Method => false,
StructField => false, // Only in structs or variants
Variant => false, // Only in enums
}
}
pub fn can_appear_in_trait(self) -> bool {
match self {
Kind::AssocConst => true,
Kind::AssocType => true,
Kind::Method => true,
Kind::Module => false,
Kind::ExternCrate => false,
Kind::Import => false,
Kind::Struct => false,
Kind::StructField => false,
Kind::Union => false,
Kind::Enum => false,
Kind::Variant => false,
Kind::Function => false,
Kind::Typedef => false,
Kind::OpaqueTy => false,
Kind::Constant => false,
Kind::Trait => false,
Kind::TraitAlias => false,
Kind::Impl => false,
Kind::Static => false,
Kind::ForeignType => false,
Kind::Macro => false,
Kind::ProcAttribute => false,
Kind::ProcDerive => false,
Kind::Primitive => false,
Kind::Keyword => false,
Kind::ProcMacro => false,
}
}
pub fn is_struct_field(self) -> bool {
matches!(self, Kind::StructField)
}
pub fn is_module(self) -> bool {
matches!(self, Kind::Module)
}
pub fn is_impl(self) -> bool {
matches!(self, Kind::Impl)
}
pub fn is_variant(self) -> bool {
matches!(self, Kind::Variant)
}
pub fn is_trait(self) -> bool {
matches!(self, Kind::Trait)
}
pub fn is_struct_enum_union(self) -> bool {
matches!(self, Kind::Struct | Kind::Enum | Kind::Union)
}
pub fn from_item(i: &Item) -> Self {
use Kind::*;
match i.inner {
ItemEnum::Module(_) => Module,
ItemEnum::Import(_) => Import,
ItemEnum::Union(_) => Union,
ItemEnum::Struct(_) => Struct,
ItemEnum::StructField(_) => StructField,
ItemEnum::Enum(_) => Enum,
ItemEnum::Variant(_) => Variant,
ItemEnum::Function(_) => Function,
ItemEnum::Trait(_) => Trait,
ItemEnum::TraitAlias(_) => TraitAlias,
ItemEnum::Method(_) => Method,
ItemEnum::Impl(_) => Impl,
ItemEnum::Typedef(_) => Typedef,
ItemEnum::OpaqueTy(_) => OpaqueTy,
ItemEnum::Constant(_) => Constant,
ItemEnum::Static(_) => Static,
ItemEnum::Macro(_) => Macro,
ItemEnum::ProcMacro(_) => ProcMacro,
ItemEnum::Primitive(_) => Primitive,
ItemEnum::ForeignType => ForeignType,
ItemEnum::ExternCrate { .. } => ExternCrate,
ItemEnum::AssocConst { .. } => AssocConst,
ItemEnum::AssocType { .. } => AssocType,
}
}
pub fn from_summary(s: &ItemSummary) -> Self {
use Kind::*;
match s.kind {
ItemKind::AssocConst => AssocConst,
ItemKind::AssocType => AssocType,
ItemKind::Constant => Constant,
ItemKind::Enum => Enum,
ItemKind::ExternCrate => ExternCrate,
ItemKind::ForeignType => ForeignType,
ItemKind::Function => Function,
ItemKind::Impl => Impl,
ItemKind::Import => Import,
ItemKind::Keyword => Keyword,
ItemKind::Macro => Macro,
ItemKind::Method => Method,
ItemKind::Module => Module,
ItemKind::OpaqueTy => OpaqueTy,
ItemKind::Primitive => Primitive,
ItemKind::ProcAttribute => ProcAttribute,
ItemKind::ProcDerive => ProcDerive,
ItemKind::Static => Static,
ItemKind::Struct => Struct,
ItemKind::StructField => StructField,
ItemKind::Trait => Trait,
ItemKind::TraitAlias => TraitAlias,
ItemKind::Typedef => Typedef,
ItemKind::Union => Union,
ItemKind::Variant => Variant,
}
}
}
|