(input: DeriveInput)
| 11 | } |
| 12 | |
| 13 | pub fn derive(input: DeriveInput) -> Result<TokenStream> { |
| 14 | let atom = atom_from_attrs(&input.attrs).ok_or_else(|| { |
| 15 | Error::new(input.ident.span(), "#[derive(FeatureMetadata)] requires #[feature_metadata(CssAtomSet::Atom)]") |
| 16 | })?; |
| 17 | |
| 18 | let ident = &input.ident; |
| 19 | let (impl_generics, type_generics, where_clause) = input.generics.split_for_impl(); |
| 20 | |
| 21 | let variants = match &input.data { |
| 22 | Data::Enum(e) => &e.variants, |
| 23 | _ => return Err(Error::new(ident.span(), "#[derive(FeatureMetadata)] requires an enum")), |
| 24 | }; |
| 25 | |
| 26 | let mut arms = Vec::new(); |
| 27 | |
| 28 | for variant in variants { |
| 29 | let vname = &variant.ident; |
| 30 | match vname.to_string().as_str() { |
| 31 | // discrete_feature! / boolean_feature! colon form |
| 32 | "WithValue" => { |
| 33 | arms.push(quote! { |
| 34 | Self::WithValue(_, _, _, value, _) => { |
| 35 | use css_lexer::ToSpan; |
| 36 | crate::ConditionalFeature::Plain { |
| 37 | name: #atom, |
| 38 | value: Some(value.to_span()), |
| 39 | } |
| 40 | } |
| 41 | }); |
| 42 | } |
| 43 | // discrete_feature! / boolean_feature! bare form |
| 44 | "Bare" => { |
| 45 | arms.push(quote! { |
| 46 | Self::Bare(_, _, _) => crate::ConditionalFeature::Plain { |
| 47 | name: #atom, |
| 48 | value: None, |
| 49 | } |
| 50 | }); |
| 51 | } |
| 52 | // ranged_feature! exact colon form |
| 53 | "Exact" => { |
| 54 | arms.push(quote! { |
| 55 | Self::Exact(_, _, _, value, _) => { |
| 56 | use css_lexer::ToSpan; |
| 57 | crate::ConditionalFeature::Ranged { |
| 58 | name: #atom, |
| 59 | form: crate::RangedForm::Exact { value: value.to_span() }, |
| 60 | } |
| 61 | } |
| 62 | }); |
| 63 | } |
| 64 | // ranged_feature! legacy min form |
| 65 | "Min" => { |
| 66 | arms.push(quote! { |
| 67 | Self::Min(_, _, _, value, _) => { |
| 68 | use css_lexer::ToSpan; |
| 69 | crate::ConditionalFeature::Ranged { |
| 70 | name: #atom, |
nothing calls this directly
no test coverage detected