Skip to main content

ItemExt

Trait ItemExt 

Source
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§

Source

fn is_struct(&self) -> bool

Returns true if this is Item::Struct.

Source

fn is_enum(&self) -> bool

Returns true if this is Item::Enum.

Source

fn is_union(&self) -> bool

Returns true if this is Item::Union.

Source

fn is_fn(&self) -> bool

Returns true if this is Item::Fn.

Source

fn is_trait(&self) -> bool

Returns true if this is Item::Trait.

Source

fn is_impl(&self) -> bool

Returns true if this is Item::Impl.

Source

fn is_mod(&self) -> bool

Returns true if this is Item::Mod.

Source

fn is_type(&self) -> bool

Returns true if this is Item::Type.

Source

fn is_const(&self) -> bool

Returns true if this is Item::Const.

Source

fn is_static(&self) -> bool

Returns true if this is Item::Static.

Source

fn is_use(&self) -> bool

Returns true if this is Item::Use.

Source

fn as_struct(&self) -> Option<&ItemStruct>

Returns the inner syn::ItemStruct if this is a struct.

Source

fn as_enum(&self) -> Option<&ItemEnum>

Returns the inner syn::ItemEnum if this is an enum.

Source

fn as_union(&self) -> Option<&ItemUnion>

Returns the inner syn::ItemUnion if this is a union.

Source

fn as_fn(&self) -> Option<&ItemFn>

Returns the inner syn::ItemFn if this is a function.

Source

fn as_trait(&self) -> Option<&ItemTrait>

Returns the inner syn::ItemTrait if this is a trait.

Source

fn as_impl(&self) -> Option<&ItemImpl>

Returns the inner syn::ItemImpl if this is an impl block.

Source

fn as_mod(&self) -> Option<&ItemMod>

Returns the inner syn::ItemMod if this is a module.

Source

fn as_type(&self) -> Option<&ItemType>

Returns the inner syn::ItemType if this is a type alias.

Source

fn as_const(&self) -> Option<&ItemConst>

Returns the inner syn::ItemConst if this is a constant.

Source

fn as_static(&self) -> Option<&ItemStatic>

Returns the inner syn::ItemStatic if this is a static.

Source

fn as_use(&self) -> Option<&ItemUse>

Returns the inner syn::ItemUse if this is a use declaration.

Source

fn attrs(&self) -> &[Attribute]

Returns the attributes for this item. All variants have attributes.

Source

fn ident(&self) -> Option<&Ident>

Returns the identifier if this variant has one. Returns None for Impl, Use, ForeignMod, and Verbatim.

Source

fn generics(&self) -> Option<&Generics>

Returns the generics if this variant has them. Returns None for variants without generic parameters.

Source

fn vis(&self) -> Option<&Visibility>

Returns the visibility if this variant has one. Returns None for Impl, ForeignMod, and Verbatim.

Source

fn span(&self) -> Span

Returns the span of this item.

Implementations on Foreign Types§

Source§

impl ItemExt for Item

Implementors§