pub trait Generator {
fn next_id(&mut self) -> u8;
}
impl<T> Generator for &mut T
where
T: Generator,
{
fn next_id(&mut self) -> u8 {
(*self).next_id()
}
}
#[derive(Debug, Default)]
pub struct Counter {
last_id: u8,
}
impl Generator for Counter {
fn next_id(&mut self) -> u8 {
self.last_id = (self.last_id + 1) % 100;
self.last_id
}
}