1use std::marker::PhantomData;
2use std::ops::RangeFrom;
3
4pub trait Gen {
5 type Output;
6
7 fn next(&mut self) -> Option<Self::Output>;
8}
9
10#[derive(
11 Clone,
12 Debug,
13)]
14pub struct Generator<T> {
15 generator: RangeFrom<u128>,
16 marker: PhantomData<T>,
17}
18
19impl<T: From<u128>> Generator<T> {
20 pub fn new() -> Self {
21 Generator {
22 generator: 0..,
23 marker: PhantomData,
24 }
25 }
26}
27
28impl<T: From<u128>> Gen for Generator<T> {
29 type Output = T;
30
31 fn next(&mut self) -> Option<Self::Output> {
32 self.generator.next().map(|i| i.into())
33 }
34}
35
36impl<T: From<u128>> Default for Generator<T> {
37 fn default() -> Self {
38 Generator::new()
39 }
40}