use std::hash::Hash;
use std::hash::Hasher;
use std::marker::PhantomData;
#[derive(Debug, Copy, Clone, Eq, Hash, PartialEq)]
pub struct ValueHandle {
pub(super) index: slotmap::DefaultKey,
}
impl ValueHandle {
pub(super) fn new(index: slotmap::DefaultKey) -> Self {
Self { index }
}
}
#[derive(Debug)]
pub struct TypedValueHandle<T> {
handle: ValueHandle,
_data: PhantomData<T>,
}
impl<T> TypedValueHandle<T> {
pub(crate) fn new_unchecked(handle: ValueHandle) -> Self {
Self {
handle,
_data: PhantomData,
}
}
pub fn into_raw(self) -> ValueHandle {
self.handle
}
}
impl<T> Clone for TypedValueHandle<T> {
fn clone(&self) -> Self {
*self
}
}
impl<T> Copy for TypedValueHandle<T> {}
impl<T> PartialEq<Self> for TypedValueHandle<T> {
fn eq(&self, other: &Self) -> bool {
self.handle.eq(&other.handle)
}
}
impl<T> Eq for TypedValueHandle<T> {}
impl<T> Hash for TypedValueHandle<T> {
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
self.handle.hash(state)
}
}
impl<T> From<TypedValueHandle<T>> for ValueHandle {
fn from(handle: TypedValueHandle<T>) -> Self {
handle.into_raw()
}
}