dumbledore/archetypes/
mod.rs1pub mod arche;
2
3use crate::component::Component;
4use std::alloc::Layout;
5use std::any::TypeId;
6use std::cmp::Ordering;
7
8#[derive(Debug, Clone)]
10pub struct ComponentInfo {
11 pub(crate) layout: Layout,
12 pub(crate) id: TypeId,
13 pub(crate) drop: unsafe fn(*mut u8),
14}
15
16impl ComponentInfo {
17 pub fn new<T: Component>() -> Self {
18 unsafe fn drop_ptr<T>(ptr: *mut u8) {
19 ptr.drop_in_place()
20 }
21
22 ComponentInfo {
23 layout: Layout::new::<T>(),
24 id: TypeId::of::<T>(),
25 drop: drop_ptr::<T>,
26 }
27 }
28}
29
30impl PartialEq<Self> for ComponentInfo {
31 fn eq(&self, other: &Self) -> bool {
32 self.id == other.id
33 }
34}
35
36impl Eq for ComponentInfo {}
37
38impl Ord for ComponentInfo {
39 fn cmp(&self, other: &Self) -> Ordering {
40 self.layout
41 .align()
42 .cmp(&other.layout.align())
43 .reverse()
44 .then_with(|| self.id.cmp(&other.id))
45 }
46}
47
48impl PartialOrd for ComponentInfo {
49 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
50 Some(self.cmp(other))
51 }
52}