Conditional impl Trait in proc macro?

Hi Dear Community,

Suppose i got this trait, is it possible to conditionally impl this trait in derive procedure macro?

Trait A {
#[cfg(feature = "foo")]

as the macro is used on the user's side, simply putting #[cfg(feature = "foo")] in the quote! would compile it down to the user's side.
Is there any possible way to work around this?
Or is there any cfg that can control if a dependency enabled a feature?

Many thanks!

Let's take a step back, because I smell an X/Y problem.
What do you want this for?

building an ORM, the struct is defined by user, generate method for extracting metadata of that struct

Your derive crate provides a feature called "generate-foo", and then you make the "foo" feature of your main crate depend on "my-derive-crate/generate-foo". This allows the derive crate to use #[cfg(feature = "generator-foo")].

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.