#[derive(
Debug,
Default,
PartialEq,
Eq,
PartialOrd,
Ord,
derive_more::Display,
derive_more::Into,
derive_more::From,
derive_more::Deref,
derive_more::AsRef,
)]
pub struct ArrayIndex<const N: usize>(usize);
impl<const N: usize> ArrayIndex<N> {
#[must_use]
pub const fn new() -> Self {
Self(0)
}
pub fn try_post_inc(&mut self) -> Option<usize> {
(self.0 < N).then(|| self.0.post_inc())
}
}
#[sealed::sealed]
pub trait PostInc: Copy + core::ops::AddAssign<usize> {
#[must_use]
fn post_inc(&mut self) -> Self {
let old = *self;
*self += 1;
old
}
}
#[sealed::sealed]
impl PostInc for usize {}