bon_macros/util/
item.rs

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
pub(crate) trait ItemExt {
    fn attrs_mut(&mut self) -> Option<&mut Vec<syn::Attribute>>;
}

impl ItemExt for syn::Item {
    fn attrs_mut(&mut self) -> Option<&mut Vec<syn::Attribute>> {
        let attrs = match self {
            Self::Const(item) => &mut item.attrs,
            Self::Enum(item) => &mut item.attrs,
            Self::ExternCrate(item) => &mut item.attrs,
            Self::Fn(item) => &mut item.attrs,
            Self::ForeignMod(item) => &mut item.attrs,
            Self::Impl(item) => &mut item.attrs,
            Self::Macro(item) => &mut item.attrs,
            Self::Mod(item) => &mut item.attrs,
            Self::Static(item) => &mut item.attrs,
            Self::Struct(item) => &mut item.attrs,
            Self::Trait(item) => &mut item.attrs,
            Self::TraitAlias(item) => &mut item.attrs,
            Self::Type(item) => &mut item.attrs,
            Self::Union(item) => &mut item.attrs,
            Self::Use(item) => &mut item.attrs,
            _ => return None,
        };

        Some(attrs)
    }
}