leap_lang/
handle.rs

1use std::{
2    hash::{Hash, Hasher},
3    marker::PhantomData,
4};
5
6#[derive(Debug)]
7pub struct Handle<T>(u32, PhantomData<T>);
8
9impl<T> Handle<T> {
10    #[inline]
11    pub fn new(id: u32) -> Self {
12        Self(id, PhantomData)
13    }
14
15    #[inline]
16    pub fn as_index(&self) -> usize {
17        self.0 as usize
18    }
19}
20
21impl<T> PartialEq for Handle<T> {
22    fn eq(&self, other: &Self) -> bool {
23        self.0 == other.0
24    }
25}
26
27impl<T> Eq for Handle<T> {}
28
29impl<T> Clone for Handle<T> {
30    fn clone(&self) -> Self {
31        Self::new(self.0)
32    }
33}
34
35impl<T> Copy for Handle<T> {}
36
37impl<T> Hash for Handle<T> {
38    fn hash<H: Hasher>(&self, state: &mut H) {
39        self.0.hash(state);
40    }
41}