#[derive(Foo, Bar)]
is sugar for #[derive_Foo] #[derive_Bar]
, so it is possible to implement your own decorator attribute in the same way as #[derive_Clone]
is, but this requires you to write a compiler plugin, which is not a stable part of Rust and will not be stable in 1.0 (and will thus be unavailable in the stable and beta channels).
There is a little documentation on such matters in the book, but not much; you’re largely on your own with it.
Bear in mind that what you can actually do at that stage is limited; you have access to the struct definition only, and know nothing about the actual types mentioned. This is a good fit for all of the traits for which #[derive]
support is built in, but is not for many other traits.