| 1 | use syn::{spanned::Spanned, Attribute, Error}; |
| 2 | |
| 3 | pub fn get_magnus_attribute(attrs: &[Attribute]) -> Result<Option<&Attribute>, Error> { |
| 4 | let attrs = attrs |
| 5 | .iter() |
| 6 | .filter(|attr| attr.path().is_ident("magnus")) |
| 7 | .collect::<Vec<_>>(); |
| 8 | if attrs.is_empty() { |
| 9 | return Ok(None); |
| 10 | } else if attrs.len() > 1 { |
| 11 | return Err(attrs |
| 12 | .into_iter() |
| 13 | .map(|a| Error::new(a.span(), "duplicate attribute")) |
| 14 | .reduce(|mut a, b| { |
| 15 | a.combine(b); |
| 16 | a |
| 17 | }) |
| 18 | .unwrap()); |
| 19 | } |
| 20 | Ok(Some(attrs[0])) |
| 21 | } |