I understand where you come from, but… how do two libraries communicate with each others then?
By your statement, the only way two libraries can talk to each other is either:
- exposing std types
- having the user write scaffolding to translate from one library type to the other library type
The first one is extremely restrictive, the second one is extremely boiler-platey (wasteful, error-prone, and a performance issue).
I am afraid that having a library accept, in its public API, a type created by another library (such as a Matrix) cannot be avoided. To push the reasoning to an extreme, proprietary code will not come put its XyConsumer type in the standard library, and yet many of the libraries defined in their repositories might need to access such a consumer.
Composition of 3rd-party libraries is necessary.
That being said, circumventing the orphan rule may not be the best solution. After all, Rust has 0-cost newtypes.
Today automatic derivation does not work for such newtypes, because it expects the inner type to implement the trait whereas the lack of implementation is precisely the reason why the newtype is necessary in the first place. Still, that’s just a short-coming of the derivation today, and maybe it could be solved generically.
(After, there’s still the issue of the newtype require wrapping/unwrapping, Deref, AsRef, From, etc… can probably help here)