#[macro_export]
macro_rules! index_struct {
($(#[$m:meta])* $v:vis struct $n:ident {
$vf:vis value: usize,
}) => {
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
$(#[$m])*
$v struct $n {
$vf value: usize,
}
impl $n {
#[allow(dead_code)]
$v fn get_and_increment(&mut self) -> Self {
let old_value = *self;
self.increment();
old_value
}
#[allow(dead_code)]
$v fn increment(&mut self) {
self.value += 1;
}
pub fn iterate_range(range: ::std::ops::Range<Self>) -> impl Iterator<Item = $n> {
(range.start.value..range.end.value).into_iter().map(|i| Self { value: i })
}
}
impl ::std::fmt::Debug for $n {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
write!(fmt, "{}({})", stringify!($n), self.value)
}
}
impl From<usize> for $n {
fn from(value: usize) -> Self {
Self { value }
}
}
}
}