1 | use syn::NestedMeta; |
2 | |
3 | use crate::util::PathList; |
4 | use crate::{FromMeta, Result}; |
5 | |
6 | /// A rule about which attributes to forward to the generated struct. |
7 | #[derive (Debug, Clone, PartialEq, Eq)] |
8 | pub enum ForwardAttrs { |
9 | All, |
10 | Only(PathList), |
11 | } |
12 | |
13 | impl ForwardAttrs { |
14 | /// Returns `true` if this will not forward any attributes. |
15 | pub fn is_empty(&self) -> bool { |
16 | match *self { |
17 | ForwardAttrs::All => false, |
18 | ForwardAttrs::Only(ref list: &PathList) => list.is_empty(), |
19 | } |
20 | } |
21 | } |
22 | |
23 | impl FromMeta for ForwardAttrs { |
24 | fn from_word() -> Result<Self> { |
25 | Ok(ForwardAttrs::All) |
26 | } |
27 | |
28 | fn from_list(nested: &[NestedMeta]) -> Result<Self> { |
29 | Ok(ForwardAttrs::Only(PathList::from_list(items:nested)?)) |
30 | } |
31 | } |
32 | |