pub trait Dummy: Sized {
// Required method
fn dummy() -> Self;
}
Expand description
A trait for giving a type a dummy value.
Sometimes in tests you need to provide a value for a type, but the actual value doesn’t matter. This trait allows defining a “dummy” value for a type, separated from an eventual default value, that can be reused across multiple tests.
Note: should not be confused with “fake” values, fake values aim to be believable and contain valid cryptography (if they have some), dummies don’t aim for those characteristics.
§Example
use mithril_common::test::double::Dummy;
struct MyType(String);
impl Dummy for MyType {
fn dummy() -> Self {
MyType("whatever".to_string())
}
}
let instance = MyType::dummy();
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.