I'm using a macro to extend a primitive struct:
pub struct MyTypedNumber(pub u32);
struct_impl_my_features!(MyTypedNumber);
The struct_impl_my_features macro can implement functions & traits for MyTypedNumber, however there is a case where its useful to use #[derive(PartialEq, Eq)] - for example.
Is it possible to use #[derive(...)] after the struct is already declared?
An alternative is to pass in the struct definition as an item argument to a macro:
struct_impl_my_features!(
pub struct MyTypedNumber(pub u32);,
MyTypedNumber
);
This works, so it may be the best option, although it is rather clunky and means the declaration and macro extension must be together.
See this complete example, the macro is called struct_bitflag_impl (second example).
I worked around this by manually implementing PartialEq and Eq, however I ran into a case where Rust needs #[derive(...)] to be used as constants within match statement:
= warning: this was previously accepted by the compiler but is being phased out;
it will become a hard error in a future release!
= note: for more information,
see RFC 1445 <https://github.com/rust-lang/rfcs/pull/1445>
MyTypedIntaccidentally left in, corrected - added link to complete example. - ideasman42