Warning
This post was published 49 days ago. The information described in this article may have changed.
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.
1 post - 1 participant
🏷️ rust_feed