mod inner;
use {
core::ops::RangeTo,
self::inner::Inner,
};
#[derive(Debug)]
pub struct ArrayIndexes<'a, const N: usize> {
inner: Inner<'a, N>,
}
impl<const N: usize> ArrayIndexes<'_, N> {
pub (crate) fn iter(&self) -> impl Iterator<Item=&usize> {
match &self.inner {
Inner::Slice(slice) => slice.iter(),
Inner::Array(array) => array.iter(),
}
}
pub (crate) fn len(&self) -> usize {
match &self.inner {
Inner::Slice(slice) => slice.len(),
Inner::Array(array) => array.len(),
}
}
pub (crate) fn index_with_range_to(&self, range: RangeTo<usize>) -> &[usize] {
&self.inner[range]
}
}
impl From<usize> for ArrayIndexes<'_, 1> {
fn from(index: usize) -> Self {
Self {
inner: Inner::Array([index]),
}
}
}
impl<const N: usize> From<[usize; N]> for ArrayIndexes<'_, N> {
fn from(indexes: [usize; N]) -> Self {
Self {
inner: Inner::Array(indexes),
}
}
}
impl<'a> From<&'a [usize]> for ArrayIndexes<'a, 0> {
fn from(indexes: &'a [usize]) -> Self {
Self {
inner: Inner::Slice(indexes),
}
}
}