Provides parser-combinator-like combinable text generation in Rust.
You can add this crate to your Rust project with generator-combinator = "0.1.0"
. Documentation on docs.rs and crates.io listing.
To generate street address-like input, only a few components are required. We can quickly produce a range of nearly 1B possible values that can be fully iterated over or randomly sampled:
```rust use generator_combinator::Generator; let space = Generator::from(' ');
let number = Generator::Digit * (3, 5);
let directional = space.clone() + oneof!("N", "E", "S", "W", "NE", "SE", "SW", "NW"); let streetnames = space.clone() + oneof!("Boren", "Olive", "Spring", "Cherry", "Seneca", "Yesler", "Madison", "James", "Union", "Mercer"); let streetsuffixes = space.clone() + oneof!("Rd", "St", "Ave", "Blvd", "Ln", "Dr", "Way", "Ct", "Pl");
let address = number // street number is 3-5 digits long + directional.clone().optional() // optional pre-directional + streetnames + streetsuffixes + directional.clone().optional(); // optional post-directional
asserteq!(address.len(), 809190_000);
let addrvalues = address.values(); println!("Example: {}", addrvalues.random()); //Example: 344 W Yesler Way println!("Example: {}", addrvalues.random()); //Example: 702 NE Spring Ct N println!("Example: {}", addrvalues.random()); //Example: 803 SW Madison Way SE ```
This library is 0.1.0 - there may be issues, functionality may be incomplete, etc.
Fn
variants of Generator
Generator
post-processing of component strings (eg, to strip leading zeros) before combining output