How to verify that a trait implementation is "complete", doesn't use any trait default methods?

Let's assume there is a trait MyTrait implemented by for the AnImpl struct.
I want to implement a decorator pattern over the AnImpl. Let's call this new type TheDecorator.

I want the TheDecorator to implement every MyTrait method. Some will be trivially delegated to the inner AnImpl instance, some not (depending on the logic of the decorator). I do not want the TheDecorator to rely on any MyTrait default method.

So far this is easy -- just implement every method. Let's now assume that MyTrait is expected to evolve, possibly gaining new default methods. How to make sure the TheDecorator remains "fully implemented", i.e. maintains the invariant that it does not rely on any MyTrait default method?

Context:
I am coming from Java background where decorators are idiomatic. Having automated checks for invariants as above saved my day many times over. I don't find decorators anti-idiomatic in Rust and so would love to have these checks.

You can do this with clippy's missing_trait_methods: "Checks if a provided method is used implicitly by a trait implementation."

4 Likes

that's exactly this. Thanks!

Side note: I find that java code I read tends to overly rely on abstractions where they aren't needed. I'm not saying that decorators are bad, just that the typical enterprisy java code I have seen has an overreliance on design patterns in general.

(Maybe the issue here isn't java, but the contexts in which java is used. I have come across DecoratorFactoryBuilders in C++ too, just not as often.)

(I have yet to see that in Rust thankfully, but instead we get type state builders and complex macros even when not needed.)

Context: I have a C++ background before going to Rust, and I really dislike java (having now successfully avoided it in a professional context for well over a decade, having last used java on Android during my bachelor thesis). I also know Erlang, Python, some Haskell, and bits and pieces of a dozen or so other languages.