In general I understand why the “private traits in public interfaces” thing is going away, but I’ve run into a case in which it seems like it should be allowed. I’m wondering whether there’s an obvious way to do this differently that I’m missing?
The problem is the following: I’ve defined a data structure in a non-public sub-module. Since it’s in a sub-module, the type itself needs to be public so that code from my top-level module can use it. It can only be parametrized on types that implement a particular trait which is defined in the top-level module, but is not public. Thus, I run into a conundrum:
- I can’t make the type non-public because I need to be able to access it from the top-level module. Note that this doesn’t break the spirit behind a “private trait in a public interface” - the module it’s in is not public, so nobody outside of my top-level module could see the private trait.
- I can’t move the trait into the sub-module because other sub-modules and code in the top-level module need to use it.
I’ve reproduced a toy example of this issue here. I was able to get my code to compile by moving the trait bound out of the type definition and into the
impl (see here for an equivalent toy example), but as the warning on the code suggests, this will soon be illegal too.