1 use rustdoc_json_types::{Item, ItemEnum, ItemKind, ItemSummary};
3 /// A univeral way to represent an [`ItemEnum`] or [`ItemKind`]
4 #[derive(Debug, Clone, Copy)]
35 pub fn can_appear_in_mod(self) -> bool {
56 // FIXME(adotinthevoid): I'm not sure if these are corrent
59 ProcAttribute => false,
66 StructField => false, // Only in structs or variants
67 Variant => false, // Only in enums
71 pub fn can_appear_in_import(self) -> bool {
73 Kind::Variant => true,
74 Kind::Import => false,
75 other => other.can_appear_in_mod(),
79 pub fn can_appear_in_glob_import(self) -> bool {
87 pub fn can_appear_in_trait(self) -> bool {
89 Kind::AssocConst => true,
90 Kind::AssocType => true,
91 Kind::Function => true,
93 Kind::Module => false,
94 Kind::ExternCrate => false,
95 Kind::Import => false,
96 Kind::Struct => false,
97 Kind::StructField => false,
100 Kind::Variant => false,
101 Kind::Typedef => false,
102 Kind::OpaqueTy => false,
103 Kind::Constant => false,
104 Kind::Trait => false,
105 Kind::TraitAlias => false,
107 Kind::Static => false,
108 Kind::ForeignType => false,
109 Kind::Macro => false,
110 Kind::ProcAttribute => false,
111 Kind::ProcDerive => false,
112 Kind::Primitive => false,
113 Kind::Keyword => false,
114 Kind::ProcMacro => false,
118 pub fn is_struct_field(self) -> bool {
119 matches!(self, Kind::StructField)
121 pub fn is_module(self) -> bool {
122 matches!(self, Kind::Module)
124 pub fn is_impl(self) -> bool {
125 matches!(self, Kind::Impl)
127 pub fn is_variant(self) -> bool {
128 matches!(self, Kind::Variant)
130 pub fn is_trait_or_alias(self) -> bool {
131 matches!(self, Kind::Trait | Kind::TraitAlias)
133 pub fn is_type(self) -> bool {
134 matches!(self, Kind::Struct | Kind::Enum | Kind::Union | Kind::Typedef)
137 pub fn from_item(i: &Item) -> Self {
140 ItemEnum::Module(_) => Module,
141 ItemEnum::Import(_) => Import,
142 ItemEnum::Union(_) => Union,
143 ItemEnum::Struct(_) => Struct,
144 ItemEnum::StructField(_) => StructField,
145 ItemEnum::Enum(_) => Enum,
146 ItemEnum::Variant(_) => Variant,
147 ItemEnum::Function(_) => Function,
148 ItemEnum::Trait(_) => Trait,
149 ItemEnum::TraitAlias(_) => TraitAlias,
150 ItemEnum::Impl(_) => Impl,
151 ItemEnum::Typedef(_) => Typedef,
152 ItemEnum::OpaqueTy(_) => OpaqueTy,
153 ItemEnum::Constant(_) => Constant,
154 ItemEnum::Static(_) => Static,
155 ItemEnum::Macro(_) => Macro,
156 ItemEnum::ProcMacro(_) => ProcMacro,
157 ItemEnum::Primitive(_) => Primitive,
158 ItemEnum::ForeignType => ForeignType,
159 ItemEnum::ExternCrate { .. } => ExternCrate,
160 ItemEnum::AssocConst { .. } => AssocConst,
161 ItemEnum::AssocType { .. } => AssocType,
165 pub fn from_summary(s: &ItemSummary) -> Self {
168 ItemKind::AssocConst => AssocConst,
169 ItemKind::AssocType => AssocType,
170 ItemKind::Constant => Constant,
171 ItemKind::Enum => Enum,
172 ItemKind::ExternCrate => ExternCrate,
173 ItemKind::ForeignType => ForeignType,
174 ItemKind::Function => Function,
175 ItemKind::Impl => Impl,
176 ItemKind::Import => Import,
177 ItemKind::Keyword => Keyword,
178 ItemKind::Macro => Macro,
179 ItemKind::Module => Module,
180 ItemKind::OpaqueTy => OpaqueTy,
181 ItemKind::Primitive => Primitive,
182 ItemKind::ProcAttribute => ProcAttribute,
183 ItemKind::ProcDerive => ProcDerive,
184 ItemKind::Static => Static,
185 ItemKind::Struct => Struct,
186 ItemKind::StructField => StructField,
187 ItemKind::Trait => Trait,
188 ItemKind::TraitAlias => TraitAlias,
189 ItemKind::Typedef => Typedef,
190 ItemKind::Union => Union,
191 ItemKind::Variant => Variant,