From 931e2c4e43fde6a308ee9933538142ed0927f6d9 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Mon, 2 Mar 2026 10:46:19 +0100 Subject: [PATCH] feat: Provide an '.item_kind()' method on ItemEnum --- src/rustdoc-json-types/lib.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/rustdoc-json-types/lib.rs b/src/rustdoc-json-types/lib.rs index 9a59de4f844a..3c696f506dd8 100644 --- a/src/rustdoc-json-types/lib.rs +++ b/src/rustdoc-json-types/lib.rs @@ -682,6 +682,39 @@ pub enum ItemEnum { }, } +impl ItemEnum { + /// Returns the [`ItemKind`] of this item. + pub fn item_kind(&self) -> ItemKind { + match self { + ItemEnum::Module(_) => ItemKind::Module, + ItemEnum::ExternCrate { .. } => ItemKind::ExternCrate, + ItemEnum::Use(_) => ItemKind::Use, + ItemEnum::Union(_) => ItemKind::Union, + ItemEnum::Struct(_) => ItemKind::Struct, + ItemEnum::StructField(_) => ItemKind::StructField, + ItemEnum::Enum(_) => ItemKind::Enum, + ItemEnum::Variant(_) => ItemKind::Variant, + ItemEnum::Function(_) => ItemKind::Function, + ItemEnum::Trait(_) => ItemKind::Trait, + ItemEnum::TraitAlias(_) => ItemKind::TraitAlias, + ItemEnum::Impl(_) => ItemKind::Impl, + ItemEnum::TypeAlias(_) => ItemKind::TypeAlias, + ItemEnum::Constant { .. } => ItemKind::Constant, + ItemEnum::Static(_) => ItemKind::Static, + ItemEnum::ExternType => ItemKind::ExternType, + ItemEnum::Macro(_) => ItemKind::Macro, + ItemEnum::ProcMacro(pm) => match pm.kind { + MacroKind::Bang => ItemKind::Macro, + MacroKind::Attr => ItemKind::ProcAttribute, + MacroKind::Derive => ItemKind::ProcDerive, + }, + ItemEnum::Primitive(_) => ItemKind::Primitive, + ItemEnum::AssocConst { .. } => ItemKind::AssocConst, + ItemEnum::AssocType { .. } => ItemKind::AssocType, + } + } +} + /// A module declaration, e.g. `mod foo;` or `mod foo {}`. #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub struct Module {