#[dummies]Expand description
Generates a “dummy” implementation for each method in a trait and implements the trait for Dummy.
This eases implementing test doubles in cases there the test does not require all the methods of a trait. The compiler is happy as there is a default implementation and you can focus on overwriting the behavior which is of interest to your test.
-
Most default implementations will call
unimplemented!. -
Existing default implementations are respected and not overridden.
-
Methods returning
implTrait will not work unless they are specifically supproted by this crate. One way to deal with this, is to give them an explicit default implementation in the test case. E.g.,#[cfg_attr(test, double_trait::dummies)] trait MyTrait { #[cfg(not(test))] fn answer(&self) -> impl Answer; // `dummies` can not interfere a type for `impl Answer`, so we provide a default impl here. #[cfg(test)] fn answer(&self) -> impl Answer { DummyAnswer } // ... other methods ... } -
Associated types are implemented using
Dummy. -
Async methods and methods returning
impl Futureare supported and inherit the default from their sync counterparts. -
Methods returning
impl Iteratorare supported and will return an empty iterator. -
Methods returning
impl Streamare supported if thestreamfeature is activated and will return an empty Stream. -
Methods returning
Result, will use the default behavior of theOktype and wrap it inOk. -
Methods returning
Optionwill returnNone.