-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
feat: Provide an '.item_kind()' method on ItemEnum #153279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmmm, maybe we should merge these in ItemKind, or split them in ItemEnum. (But not in this PR)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, it does violate the overall |
||
| 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 { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: This doc comment doesn't say anything that isn't in the function signature. Maybe add a sentance or an example about why you'd want to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's one of those methods where it's difficult to be insightful in doc comments 😅