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
use std::hash::Hash;
use crate::{ReplicaRefWrapper, Replicate, WorldRefType};
pub struct EntityRef<E: Copy + Eq + Hash, W: WorldRefType<E>> {
world: W,
entity: E,
}
impl<E: Copy + Eq + Hash, W: WorldRefType<E>> EntityRef<E, W> {
pub fn new(world: W, entity: &E) -> Self {
EntityRef {
world,
entity: *entity,
}
}
pub fn id(&self) -> E {
self.entity
}
pub fn has_component<R: Replicate>(&self) -> bool {
self.world.has_component::<R>(&self.entity)
}
pub fn component<R: Replicate>(&self) -> Option<ReplicaRefWrapper<R>> {
self.world.component::<R>(&self.entity)
}
}