pub struct Generator { /* private fields */ }Expand description
A statement writer.
Cheap to build and cheap to clone, and a run is a seed, so the same generator with the same seed writes the same statement on any machine and in any order.
Implementations§
Source§impl Generator
impl Generator
Sourcepub fn with_catalog(catalog: Catalog) -> Self
pub fn with_catalog(catalog: Catalog) -> Self
A generator over a catalog somebody else built, which is the case that matters.
Sourcepub fn budget(self, tokens: u32) -> Self
pub fn budget(self, tokens: u32) -> Self
How many tokens to write before finishing as cheaply as possible.
Sourcepub fn repeats(self, times: u32) -> Self
pub fn repeats(self, times: u32) -> Self
How many times one rule may appear on the path from the root before the same thing happens.
One is every statement written with no nesting in it at all. Three is a couple of levels of subquery and of arithmetic, which is where the interesting shapes are.
Sourcepub fn statement(&self, seed: u64) -> String
pub fn statement(&self, seed: u64) -> String
One statement, from this seed.
§Panics
Never, in the sense that matters: the rule it writes from is one of the 1088 in the table
and every_rule_in_the_table_can_be_written_down says every one of those has a finite text.
Sourcepub fn from_rule(&self, rule: &str, seed: u64) -> Result<String>
pub fn from_rule(&self, rule: &str, seed: u64) -> Result<String>
One piece of a statement, from a named rule.
For a harness that wants expressions rather than statements, and for the tests, which are
much easier to read over Expression than over Statement.
§Errors
There is no rule with that name, or there is and nothing finite can be written from it.