pub struct ArrayProxy<T, const COUNT: usize, const STRIDE: usize> {
_array: marker::PhantomData<T>,
}
#[allow(clippy::len_without_is_empty)]
impl<T, const C: usize, const S: usize> ArrayProxy<T, C, S> {
pub unsafe fn get_ref(&self, index: usize) -> &T {
let base = self as *const Self as usize;
let address = base + S * index;
&*(address as *const T)
}
pub fn get(&self, index: usize) -> Option<&T> {
if index < C {
Some(unsafe { self.get_ref(index) })
} else {
None
}
}
pub fn len(&self) -> usize {
C
}
}
impl<T, const C: usize, const S: usize> core::ops::Index<usize> for ArrayProxy<T, C, S> {
type Output = T;
fn index(&self, index: usize) -> &T {
#[allow(clippy::no_effect)]
[(); C][index];
unsafe { self.get_ref(index) }
}
}