Multiple Default Trait Implementations (multi-default-trait-impl)
Define multiple default implementations for a trait.
This library contains two attribute macros: default_trait_impl
which defines a default trait
implementation, and trait_impl
which uses a default trait implementation you've defined.
This is particularly useful in testing, when many of your mocked types will have very similar trait implementations, but do not want the canonical default trait implementation to use mocked values.
Example
First, define a default trait implementation for the trait Car
:
NewCar
does not need to be defined beforehand.
Next, implement the new default implementation for a type:
;
;
This will ensure that our structs use the NewCar
defaults, without having to change the
canonical Car
default implementation: