I have a custom derive macro which generates some code for a struct it is applied to. That code uses few types (bytes::Buf
, ect) that need to be imported.
#[derive(MyMacro)]
struct S { ... }
What is the correct way to handle it?
If I leave it with user to add required imports to a file where my macro is used -- every time macro is changed I run a risk of breaking user code (by introducing new import requirement).
If I add required import to the generated/emitted code -- compiler complain about duplicated imports every time macro is used more than once in the same file. Plus, I run the risk of breaking user code if (after I change the macro) I introduce an import user already used.