[−][src]Macro faker_rand::faker_impl_from_file
Create a generator implementation from a file containing a list of words.
The first argument to the macro must be the name of type to create an
implementation for. Said type must be a newtype whose first member must be a
String
. The second argument must be a string literal, a path to the file
containing the list of words.
The macro will generate a
Distribution
and
Display
implementation for the type.
Each line of the given file, whose contents will be loaded using
std::include_str
, will be used as a possible value to return when the
generator is sampled.
use faker_rand::faker_impl_from_file; // First, declare your newtype wrapper around String. struct Demo(String); // Then, use the macro. data/lorem_words is a path to a file containing // example words; you will need to change this path to suit your needs. faker_impl_from_file!(Demo, "data/lorem_words"); use rand::{Rng, SeedableRng}; let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0); assert_eq!("impedit", rng.gen::<Demo>().to_string());