1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::any::Any;
use std::fmt::Debug;
use std::hash::Hash;
use std::marker::PhantomData;
use std::ops::Deref;
pub trait Component: Debug + Clone + Any + Send + Sync {}
pub trait Id: Component + Hash + Copy + Ord {}
pub trait IdWithIndex: Id {
fn max_index() -> usize;
fn index(&self) -> usize;
}
#[derive(Debug, Clone, Copy, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub struct Valid<'id, ID: Id>{
id: ID,
_phantom: PhantomData<&'id ()>,
}
impl<'id, ID: Id> Valid<'id, ID> {
pub unsafe fn new(id: ID) -> Self {
Valid{ id: id, _phantom: PhantomData }
}
}
impl<'id, ID: Id> Deref for Valid<'id, ID> {
type Target = ID;
fn deref(&self) -> &ID { &self.id }
}
pub trait Event: Debug + Clone + Any + Send + Sync {}
pub trait Action: Debug + Clone + Any + Send + Sync {}
impl<ID: Id, A: Action> Event for (ID, A) {}