use crate::IndexType;
use std::fmt::Debug;
use std::hash::Hash;
pub trait IndexKernel: Copy + Debug + Eq + Ord + Hash + 'static + Sync + Send {
const MAX: Self;
fn from_usize(value: usize) -> Self;
fn to_usize(self) -> usize;
}
impl IndexKernel for usize {
const MAX: usize = usize::MAX;
#[inline(always)]
fn from_usize(value: usize) -> Self {
value
}
#[inline(always)]
fn to_usize(self) -> usize {
self
}
}
impl IndexKernel for u32 {
const MAX: u32 = u32::MAX;
#[inline(always)]
fn from_usize(value: usize) -> Self {
value as u32 }
#[inline(always)]
fn to_usize(self) -> usize {
self as usize
}
}
impl IndexKernel for u16 {
const MAX: u16 = u16::MAX;
#[inline(always)]
fn from_usize(value: usize) -> Self {
value as u16 }
#[inline(always)]
fn to_usize(self) -> usize {
self as usize
}
}
impl<T: IndexKernel> IndexType for T {}