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
use std::{any::TypeId, hash::Hash};
use super::{
replica_ref::{ReplicaDynMut, ReplicaDynRef},
replicate::{Replicate, ReplicateSafe},
};
pub trait ProtocolType: Sized + Sync + Send + 'static {
type Kind: ProtocolKindType;
fn kind_of<R: ReplicateSafe<Self>>() -> Self::Kind;
fn type_to_kind(type_id: TypeId) -> Self::Kind;
fn dyn_ref(&self) -> ReplicaDynRef<'_, Self>;
fn dyn_mut(&mut self) -> ReplicaDynMut<'_, Self>;
fn cast<R: Replicate<Self>>(self) -> Option<R>;
fn cast_ref<R: ReplicateSafe<Self>>(&self) -> Option<&R>;
fn cast_mut<R: ReplicateSafe<Self>>(&mut self) -> Option<&mut R>;
fn extract_and_insert<N, X: ProtocolInserter<Self, N>>(&self, entity: &N, inserter: &mut X);
fn clone(&self) -> Self;
}
pub trait ProtocolKindType: Eq + Hash + Copy + Send + Sync {
fn to_u16(&self) -> u16;
fn from_u16(val: u16) -> Self;
fn to_type_id(&self) -> TypeId;
}
pub trait ProtocolInserter<P: ProtocolType, N> {
fn insert<R: ReplicateSafe<P>>(&mut self, entity: &N, component: R);
}