Trait fake::Dummy[][src]

pub trait Dummy<T>: Sized {
    fn dummy_with_rng<R: Rng + ?Sized>(config: &T, rng: &mut R) -> Self;

    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][macro@Dummy] for more.

Required methods

Generate a dummy value for a given type using a random number generator.

Provided methods

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.

Implementations on Foreign Types

Implementors