Skip to content

Commit 931e2c4

Browse files
feat: Provide an '.item_kind()' method on ItemEnum
1 parent ddd36bd commit 931e2c4

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

src/rustdoc-json-types/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,39 @@ pub enum ItemEnum {
682682
},
683683
}
684684

685+
impl ItemEnum {
686+
/// Returns the [`ItemKind`] of this item.
687+
pub fn item_kind(&self) -> ItemKind {
688+
match self {
689+
ItemEnum::Module(_) => ItemKind::Module,
690+
ItemEnum::ExternCrate { .. } => ItemKind::ExternCrate,
691+
ItemEnum::Use(_) => ItemKind::Use,
692+
ItemEnum::Union(_) => ItemKind::Union,
693+
ItemEnum::Struct(_) => ItemKind::Struct,
694+
ItemEnum::StructField(_) => ItemKind::StructField,
695+
ItemEnum::Enum(_) => ItemKind::Enum,
696+
ItemEnum::Variant(_) => ItemKind::Variant,
697+
ItemEnum::Function(_) => ItemKind::Function,
698+
ItemEnum::Trait(_) => ItemKind::Trait,
699+
ItemEnum::TraitAlias(_) => ItemKind::TraitAlias,
700+
ItemEnum::Impl(_) => ItemKind::Impl,
701+
ItemEnum::TypeAlias(_) => ItemKind::TypeAlias,
702+
ItemEnum::Constant { .. } => ItemKind::Constant,
703+
ItemEnum::Static(_) => ItemKind::Static,
704+
ItemEnum::ExternType => ItemKind::ExternType,
705+
ItemEnum::Macro(_) => ItemKind::Macro,
706+
ItemEnum::ProcMacro(pm) => match pm.kind {
707+
MacroKind::Bang => ItemKind::Macro,
708+
MacroKind::Attr => ItemKind::ProcAttribute,
709+
MacroKind::Derive => ItemKind::ProcDerive,
710+
},
711+
ItemEnum::Primitive(_) => ItemKind::Primitive,
712+
ItemEnum::AssocConst { .. } => ItemKind::AssocConst,
713+
ItemEnum::AssocType { .. } => ItemKind::AssocType,
714+
}
715+
}
716+
}
717+
685718
/// A module declaration, e.g. `mod foo;` or `mod foo {}`.
686719
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
687720
pub struct Module {

0 commit comments

Comments
 (0)