use std::marker::PhantomData;
use fastrand::Rng;
use crate::{
config::{Configuration, DefaultConfig},
Tuid,
};
pub struct Generator<C: Configuration> {
rng: Rng,
config: PhantomData<C>,
}
impl<C: Configuration> Generator<C> {
pub fn new(rng: Rng) -> Self {
Self {
rng,
config: PhantomData,
}
}
}
impl Default for Generator<DefaultConfig> {
fn default() -> Self {
Self::new(Rng::default())
}
}
impl<C: Configuration> Iterator for Generator<C> {
type Item = Tuid;
fn next(&mut self) -> Option<Self::Item> {
Some(crate::new::<C>(self.rng.u64(..), self.rng.u64(..)))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_fast_builder() {
let mut generator = Generator::default();
let _ = generator.next();
}
}