pub trait Generator where
    Self: 'static, 
{ type Output; fn generate(&mut self) -> Self::Output; }
Expand description

Something which can generate a sequence of objects of some type.

The only required function in this trait is ‘generate’ which creates a new object, mutating the generator as a byproduct. Most generators will allow customisation of the sequence of produced objects in some way.

An object implementing this trait will be automatically created for you as part of the Generatable derive macro. That generator will have a method for each field of the result type, to allow you to set a generator for the field. It will produce a default sequence (as configured by the attributes placed on the type) for every field that is not customised.

Required Associated Types

The output type.

Required Methods

Make a new object.

Example

use boulder::Generator;
struct MyGenerator {
  next: i32
};

impl Generator for MyGenerator {
  type Output = i32;
  fn generate(&mut self) -> Self::Output {
    let result = self.next;
    self.next = self.next + 1;
    result
  }
}

let mut g = MyGenerator { next: 6 };
assert_eq!(g.generate(), 6);
assert_eq!(g.generate(), 7);

Implementors