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::IndexedRandom;
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 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.
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.