| 119 | |
| 120 | impl ItemMetaInner { |
| 121 | pub fn from_nested<I>( |
| 122 | item_ident: Ident, |
| 123 | meta_ident: Ident, |
| 124 | nested: I, |
| 125 | allowed_names: &[&'static str], |
| 126 | ) -> Result<Self> |
| 127 | where |
| 128 | I: core::iter::Iterator<Item = NestedMeta>, |
| 129 | { |
| 130 | let (meta_map, lits) = nested.into_unique_map_and_lits(|path| { |
| 131 | if let Some(ident) = path.get_ident() { |
| 132 | let name = ident.to_string(); |
| 133 | if allowed_names.contains(&name.as_str()) { |
| 134 | Ok(Some(name)) |
| 135 | } else { |
| 136 | Err(err_span!( |
| 137 | ident, |
| 138 | "#[{meta_ident}({name})] is not one of allowed attributes [{}]", |
| 139 | allowed_names.iter().format(", ") |
| 140 | )) |
| 141 | } |
| 142 | } else { |
| 143 | Ok(None) |
| 144 | } |
| 145 | })?; |
| 146 | if !lits.is_empty() { |
| 147 | bail_span!(meta_ident, "#[{meta_ident}(..)] cannot contain literal") |
| 148 | } |
| 149 | |
| 150 | Ok(Self { |
| 151 | item_ident, |
| 152 | meta_ident, |
| 153 | meta_map, |
| 154 | }) |
| 155 | } |
| 156 | |
| 157 | pub fn item_name(&self) -> String { |
| 158 | self.item_ident.to_string() |