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
use specs::{Component, World, WorldExt};
use std::any;
#[derive(Copy, Clone)]
pub(crate) struct ComponentVtable {
name: &'static str,
register: fn(world: &mut World),
}
impl ComponentVtable {
pub fn for_type<T>() -> Self
where
T: Component,
T::Storage: Default,
{
ComponentVtable {
name: any::type_name::<T>(),
register: |world| {
world.register::<T>();
},
}
}
pub fn name(&self) -> &'static str { self.name }
pub(crate) fn register(&self, world: &mut World) { (self.register)(world); }
}