I want to add some arguments in my derive macro, but if I wrote this:
#[derive(MyTest(1, true))]
struct Foo {}
The compiler errored my with this: error: traits in #[derive(...)] don't accept arguments.
I think this is because the syntax is not supported by design, but I'm curious where are the "traits" come from? And any practice way to add arguments in a derive macro?
Basically, derive macros were designed for the single purpose: to generate implementation for some traits automatically, based on the struct definition. So in your code MyTest is expected to be a trait.
Probably the best way would be to add custom attributes on struct, which the derive macro will read and use. That's what derivative uses, for example.