1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! Abstraction over [`syn`] types containing something.

/// [`syn`] types containing [`syn::Attribute`]s.
pub trait Attrs {
    /// Returns contained [`syn::Attribute`]s.
    #[must_use]
    fn attrs(&self) -> &[syn::Attribute];
}

impl Attrs for Vec<syn::Attribute> {
    #[inline]
    fn attrs(&self) -> &[syn::Attribute] {
        &*self
    }
}

macro_rules! impl_attrs_for {
    ($( $ty:ty, )+) => {$(
        impl Attrs for $ty {
            #[inline]
            fn attrs(&self) -> &[syn::Attribute] {
                &*self.attrs
            }
        }
    )+}
}

impl_attrs_for! {
    syn::BareFnArg,
    syn::ConstParam,
    syn::DeriveInput,
    syn::Field,
    syn::LifetimeDef,
    syn::TypeParam,
    syn::Variadic,
    syn::Variant,
}

#[cfg(feature = "full")]
macro_rules! impl_attrs_full_for {
    ($( $ty:ty, )+) => {$(
        #[cfg_attr(docsrs, doc(cfg(feature = "full")))]
        impl Attrs for $ty {
            #[inline]
            fn attrs(&self) -> &[syn::Attribute] {
                &*self.attrs
            }
        }
    )+}
}

#[cfg(feature = "full")]
impl_attrs_full_for! {
    syn::Arm,
    syn::ExprArray,
    syn::ExprAssign,
    syn::ExprAssignOp,
    syn::ExprAsync,
    syn::ExprAwait,
    syn::ExprBinary,
    syn::ExprBlock,
    syn::ExprBox,
    syn::ExprBreak,
    syn::ExprCall,
    syn::ExprCast,
    syn::ExprClosure,
    syn::ExprContinue,
    syn::ExprField,
    syn::ExprForLoop,
    syn::ExprGroup,
    syn::ExprIf,
    syn::ExprIndex,
    syn::ExprLet,
    syn::ExprLit,
    syn::ExprLoop,
    syn::ExprMacro,
    syn::ExprMatch,
    syn::ExprMethodCall,
    syn::ExprParen,
    syn::ExprPath,
    syn::ExprRange,
    syn::ExprReference,
    syn::ExprRepeat,
    syn::ExprReturn,
    syn::ExprStruct,
    syn::ExprTry,
    syn::ExprTryBlock,
    syn::ExprTuple,
    syn::ExprType,
    syn::ExprUnary,
    syn::ExprUnsafe,
    syn::ExprWhile,
    syn::ExprYield,
    syn::FieldPat,
    syn::FieldValue,
    syn::File,
    syn::ForeignItemFn,
    syn::ForeignItemMacro,
    syn::ForeignItemStatic,
    syn::ForeignItemType,
    syn::ImplItemConst,
    syn::ImplItemMacro,
    syn::ImplItemMethod,
    syn::ImplItemType,
    syn::ItemConst,
    syn::ItemEnum,
    syn::ItemExternCrate,
    syn::ItemFn,
    syn::ItemForeignMod,
    syn::ItemImpl,
    syn::ItemMacro,
    syn::ItemMacro2,
    syn::ItemMod,
    syn::ItemStatic,
    syn::ItemStruct,
    syn::ItemTrait,
    syn::ItemTraitAlias,
    syn::ItemType,
    syn::ItemUnion,
    syn::ItemUse,
    syn::Local,
    syn::PatBox,
    syn::PatIdent,
    syn::PatLit,
    syn::PatMacro,
    syn::PatOr,
    syn::PatPath,
    syn::PatRange,
    syn::PatReference,
    syn::PatRest,
    syn::PatSlice,
    syn::PatStruct,
    syn::PatTuple,
    syn::PatTupleStruct,
    syn::PatType,
    syn::PatWild,
    syn::Receiver,
    syn::TraitItemConst,
    syn::TraitItemMacro,
    syn::TraitItemMethod,
    syn::TraitItemType,
}