I am sure there is a best practice for this, I just haven't seen it.
I have a crate common
, which defines several common things (lol) including the trait Jsonable
I have a common_macros
crate where I define a derive macro Jsonable
which references common::Jsonable
(the trait) in order to implement it.
I had everything working wonderfully including:
- Deriving the Jsonable macro in my common tests
- Deriving the Jsonable macro in other crates (like networking)
But, when I tried to derive Jsonable in common
itself, I got a missing reference error. It couldn't find the common::Jsonable
trait.
After some research, I realized I had never made common
a dependency of common_macros
. Once I did that, the rust-analyzer error went away. I could derive Jsonable.
Except that when I built common
, I got a cyclic dependency error. Because, of course, there is a cyclic dependency. common
depends on common_macros
and common_macros
depends on common
.
So, how am I supposed to do this? How do I:
- Define a trait in common for
Jsonable
- Define a macro to derive Jsonable
- Use that macro in the common crate itself