pub trait ItemExt {
Show 27 methods
// Required methods
fn is_struct(&self) -> bool;
fn is_enum(&self) -> bool;
fn is_union(&self) -> bool;
fn is_fn(&self) -> bool;
fn is_trait(&self) -> bool;
fn is_impl(&self) -> bool;
fn is_mod(&self) -> bool;
fn is_type(&self) -> bool;
fn is_const(&self) -> bool;
fn is_static(&self) -> bool;
fn is_use(&self) -> bool;
fn as_struct(&self) -> Option<&ItemStruct>;
fn as_enum(&self) -> Option<&ItemEnum>;
fn as_union(&self) -> Option<&ItemUnion>;
fn as_fn(&self) -> Option<&ItemFn>;
fn as_trait(&self) -> Option<&ItemTrait>;
fn as_impl(&self) -> Option<&ItemImpl>;
fn as_mod(&self) -> Option<&ItemMod>;
fn as_type(&self) -> Option<&ItemType>;
fn as_const(&self) -> Option<&ItemConst>;
fn as_static(&self) -> Option<&ItemStatic>;
fn as_use(&self) -> Option<&ItemUse>;
fn attrs(&self) -> &[Attribute];
fn ident(&self) -> Option<&Ident>;
fn generics(&self) -> Option<&Generics>;
fn vis(&self) -> Option<&Visibility>;
fn span(&self) -> Span;
}Expand description
Extension methods for syn::Item.
Provides variant predicates (is_struct, is_enum, is_fn, etc.),
conversions (as_struct, as_enum, as_fn, etc.), and common field
accessors (attrs, ident, generics, vis) that work across
all applicable variants.
§Examples
use zyn::ext::ItemExt;
assert!(item.is_struct());
let attrs = item.attrs();
let ident = item.ident().unwrap();Required Methods§
Sourcefn as_struct(&self) -> Option<&ItemStruct>
fn as_struct(&self) -> Option<&ItemStruct>
Returns the inner syn::ItemStruct if this is a struct.
Sourcefn as_impl(&self) -> Option<&ItemImpl>
fn as_impl(&self) -> Option<&ItemImpl>
Returns the inner syn::ItemImpl if this is an impl block.
Sourcefn as_type(&self) -> Option<&ItemType>
fn as_type(&self) -> Option<&ItemType>
Returns the inner syn::ItemType if this is a type alias.
Sourcefn as_const(&self) -> Option<&ItemConst>
fn as_const(&self) -> Option<&ItemConst>
Returns the inner syn::ItemConst if this is a constant.
Sourcefn as_static(&self) -> Option<&ItemStatic>
fn as_static(&self) -> Option<&ItemStatic>
Returns the inner syn::ItemStatic if this is a static.
Sourcefn as_use(&self) -> Option<&ItemUse>
fn as_use(&self) -> Option<&ItemUse>
Returns the inner syn::ItemUse if this is a use declaration.
Sourcefn attrs(&self) -> &[Attribute]
fn attrs(&self) -> &[Attribute]
Returns the attributes for this item. All variants have attributes.
Sourcefn ident(&self) -> Option<&Ident>
fn ident(&self) -> Option<&Ident>
Returns the identifier if this variant has one.
Returns None for Impl, Use, ForeignMod, and Verbatim.
Sourcefn generics(&self) -> Option<&Generics>
fn generics(&self) -> Option<&Generics>
Returns the generics if this variant has them.
Returns None for variants without generic parameters.
Sourcefn vis(&self) -> Option<&Visibility>
fn vis(&self) -> Option<&Visibility>
Returns the visibility if this variant has one.
Returns None for Impl, ForeignMod, and Verbatim.