Skip to content

Commit

Permalink
More anarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
arnodb committed Nov 22, 2023
1 parent 25bdfc0 commit e27f90f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 0 additions & 4 deletions src/branch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ macro_rules! alt_trait_impl(
($len:expr; $($id:ident)+) => (
impl<R, B, $($id),+> Alt<R, B> for ( $($id),+ ) where R: AntiNomRng, B: Buffer, $($id: Generator<R, B>),* {
fn choice(&mut self, rng: &mut R, buffer: &mut B) {
let anarchy = rng.anarchy();
if anarchy {
return;
}
let i = rng.gen_range(0..$len);
alt_match_arm!(0, self, rng, buffer, i; $($id)*);
}
Expand Down
10 changes: 8 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ where
R: AntiNomRng,
B: Buffer,
{
fn gen(&mut self, rng: &mut R, buffer: &mut B);
fn gen_one(&mut self, rng: &mut R, buffer: &mut B);

fn gen(&mut self, rng: &mut R, buffer: &mut B) {
if !rng.anarchy() {
self.gen_one(rng, buffer);
}
}
}

impl<R, B, F> Generator<R, B> for F
Expand All @@ -58,7 +64,7 @@ where
B: Buffer,
F: FnMut(&mut R, &mut B),
{
fn gen(&mut self, rng: &mut R, buffer: &mut B) {
fn gen_one(&mut self, rng: &mut R, buffer: &mut B) {
self(rng, buffer);
}
}

0 comments on commit e27f90f

Please sign in to comment.