With a Rust derive proc_macro, can you check if the struct derives another trait?

25 Views Asked by At

Say I want to my derive trait Builder. This creates another type FooBuilder. FooBuilder should implement Debug iff Foo also derives Debug.

#[derive(Debug, Builder)]
struct Foo {
    bar: String
}

fn main() {
   println!("{:?}", Foo::builder(); // Returns the type `FooBuilder`, works
}
#[derive(Builder)]
struct Foo {
    bar: String
}

fn main() {
   println!("{:?}", Foo::builder(); // Doesn't work, because Foo doesn't derive Debug
                                    // so FooBuilder doesn't derive Debug
}

I was trying to check the syn::DeriveInput { attrs, ... } but couldn't find the derive statements in there.

0

There are 0 best solutions below