pub trait Dummy<T>: Sized {
// Required method
fn dummy_with_rng<R: Rng + ?Sized>(config: &T, rng: &mut R) -> Self;
// Provided method
fn dummy(config: &T) -> Self { ... }
}
Expand description
Provide data structure a way to generate fake values.
The opposite of Fake
.
Faker
can be used as a generic T
for Dummy<T>
to generate a
default fake value.
Dummy
is similar to From
trait, while Fake
is similar to
Into
trait. Except in this case Fake
cannot be implemented.
Examples
use fake::{Dummy, Fake, Faker};
use rand::Rng;
use rand::seq::SliceRandom;
struct Name; // does not handle locale, see locales module for more
impl Dummy<Name> for &'static str {
fn dummy_with_rng<R: Rng + ?Sized>(_: &Name, rng: &mut R) -> &'static str {
const NAMES: &[&str] = &["John Doe", "Jane Doe"];
NAMES.choose(rng).unwrap()
}
}
let name: &str = Name.fake();
assert!(name == "John Doe" || name == "Jane Doe");
Derivable
The trait can be used with #[derive]
if all of the type’s fields
implement Fake
. See Dummy
for more.
Required Methods§
Provided Methods§
sourcefn dummy(config: &T) -> Self
fn dummy(config: &T) -> Self
Generate a dummy value for a type.
This can be left as a blanket implemented most of the time since it
uses Dummy::dummy_with_rng
under the hood.
Object Safety§
This trait is not object safe.