Skip to content

Conversation

@kraktus
Copy link

@kraktus kraktus commented Dec 22, 2022

Hello, thanks for the crate!

When looking at Item I was surprised not to find APIs that ease its use, without having to pattern-match every time, like for rustc_hir::ItemKind. This PR add a convenience method to have an easy access to the attributes of an item.

I don't know the policy about new APIs, so feel free to close if deemed out-of-scope. About the feature-flag to use and the documentation I can fix what's needed, when for parsing as a first guess.

As a side note test_expr_size and test_type_size fail on arm64 (M1).

@dtolnay dtolnay linked an issue Jan 23, 2023 that may be closed by this pull request
}

#[cfg(feature = "parsing")]
pub fn attrs(&self) -> Option<&Vec<Attribute>> {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a similar implementation of this in a crate here: parse_attributes.rs#L336

I was able to have it simply return &[Attribute], and for Item::Verbatim it just returns &[]. Not sure if that is better or not.

@mash180sx
Copy link

Why isn't this PR being merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add attrs() and attrs_mut() getters to syn::Item

3 participants