use num::{One, Unsigned};
pub trait GenIndex: Copy + Default + PartialEq + PartialOrd {
type Index: Copy + Unsigned;
type Generation: Copy + Unsigned;
fn max_generation() -> Self::Generation;
fn from_raw_parts(index: Self::Index, generation: Self::Generation) -> Self;
fn index(&self) -> Self::Index;
fn generation(&self) -> Self::Generation;
#[inline]
fn from_index(index: Self::Index) -> Self {
Self::from_raw_parts(index, Self::Generation::one())
}
#[inline]
fn null() -> Self {
Default::default()
}
#[inline]
fn is_null(&self) -> bool {
*self == Self::null()
}
#[inline]
fn next_generation(&self) -> Self {
let next_gen = self.generation();
let next_gen = if next_gen == Self::max_generation() {
Self::Generation::one()
} else {
next_gen + Self::Generation::one()
};
Self::from_raw_parts(self.index(), next_gen)
}
}