(input: &[Attribute])
| 67 | } |
| 68 | |
| 69 | pub fn get(input: &[Attribute]) -> Result<Attrs> { |
| 70 | let mut attrs = Attrs { |
| 71 | display: None, |
| 72 | source: None, |
| 73 | backtrace: None, |
| 74 | from: None, |
| 75 | transparent: None, |
| 76 | fmt: None, |
| 77 | }; |
| 78 | |
| 79 | for attr in input { |
| 80 | if attr.path().is_ident("error") { |
| 81 | parse_error_attribute(&mut attrs, attr)?; |
| 82 | } else if attr.path().is_ident("source") { |
| 83 | attr.meta.require_path_only()?; |
| 84 | if attrs.source.is_some() { |
| 85 | return Err(Error::new_spanned(attr, "duplicate #[source] attribute")); |
| 86 | } |
| 87 | let span = (attr.pound_token.span) |
| 88 | .join(attr.bracket_token.span.join()) |
| 89 | .unwrap_or(attr.path().get_ident().unwrap().span()); |
| 90 | attrs.source = Some(Source { |
| 91 | original: attr, |
| 92 | span, |
| 93 | }); |
| 94 | } else if attr.path().is_ident("backtrace") { |
| 95 | attr.meta.require_path_only()?; |
| 96 | if attrs.backtrace.is_some() { |
| 97 | return Err(Error::new_spanned(attr, "duplicate #[backtrace] attribute")); |
| 98 | } |
| 99 | attrs.backtrace = Some(attr); |
| 100 | } else if attr.path().is_ident("from") { |
| 101 | match attr.meta { |
| 102 | Meta::Path(_) => {} |
| 103 | Meta::List(_) | Meta::NameValue(_) => { |
| 104 | // Assume this is meant for derive_more crate or something. |
| 105 | continue; |
| 106 | } |
| 107 | } |
| 108 | if attrs.from.is_some() { |
| 109 | return Err(Error::new_spanned(attr, "duplicate #[from] attribute")); |
| 110 | } |
| 111 | let span = (attr.pound_token.span) |
| 112 | .join(attr.bracket_token.span.join()) |
| 113 | .unwrap_or(attr.path().get_ident().unwrap().span()); |
| 114 | attrs.from = Some(From { |
| 115 | original: attr, |
| 116 | span, |
| 117 | }); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | Ok(attrs) |
| 122 | } |
| 123 | |
| 124 | fn parse_error_attribute<'a>(attrs: &mut Attrs<'a>, attr: &'a Attribute) -> Result<()> { |
| 125 | mod kw { |
no test coverage detected