Skip to content

Commit

Permalink
fix: proc-macro properly generated VARIANTS field when enabled
Browse files Browse the repository at this point in the history
The feature had no effect, because the condition was quoted out.
  • Loading branch information
Pscheidl committed May 25, 2024
1 parent 1707a3c commit bd8223c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions enum-collections-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,30 @@ pub fn derive_enum_collections(input: TokenStream) -> TokenStream {
variants.extend(quote! { Self::#variant_name, });
}

quote! {
#[cfg(feature = "variants")]
return quote! {
impl #generics Enumerated for #name #generics {

fn position(self) -> usize {
self as usize
}

const SIZE: usize = #enum_len;
#[cfg(feature = "variants")]
const VARIANTS: &'static [Self] = &[#variants];
}
}
.into()
.into();

#[cfg(not(feature = "variants"))]
return quote! {
impl #generics Enumerated for #name #generics {

fn position(self) -> usize {
self as usize
}

const SIZE: usize = #enum_len;
}
}
.into();
}

0 comments on commit bd8223c

Please sign in to comment.