faker_rand
faker_rand
is a Rust crate that lets you easily generate fake data using the
rand
crate. It also provides macros so you can easily
build your own data generators on top of those provided out of the box.
Installation
You can use faker_rand
in your Rust project by adding the following to your
Cargo.toml
:
= "0.1"
Usage
See the docs on docs.rs for more details, but at a high level here's how you can use this crate:
use Rng;
use FirstName;
// you can display generators using "{}"
println!;
println!;
// or, you can use to_string as well
let name = .to_string;
println!;
You can also build your own generators on top of those provided by this crate, for example if you already have a file of fake data you'd like to generate:
use faker_impl_from_file;
// First, declare your newtype wrapper around 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!;
use ;
let mut rng = seed_from_u64;
assert_eq!;
Or, if you want to compose upon sub-generators:
use faker_impl_from_templates;
// First, declare your newtype wrapper around String.
;
// Then, invoke the macro.
//
// Note well: all commas and semicolons in this example, even trailing
// semicolons, are strictly required.
faker_impl_from_templates!
use ;
let mut rng = seed_from_u64;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Most of the documentation for this crate lives in the Rust docs, not this README. Check out https://docs.rs/faker_rand for copy-pastable examples you can use.