1use crate::{ecs::resources::Resources, ecs::system::Res};
2
3pub trait Dependencies<'a>: Sized {
10 fn try_gather(world: &'a hecs::World, resources: &'a Resources) -> Option<Self>;
15}
16
17impl<'a> Dependencies<'a> for () {
18 fn try_gather(_world: &'a hecs::World, _resources: &'a Resources) -> Option<Self> {
19 Some(())
20 }
21}
22
23impl<'a, A: 'static + Send + Sync> Dependencies<'a> for Res<'a, A> {
24 fn try_gather(world: &'a hecs::World, resources: &'a Resources) -> Option<Self> {
25 if !resources.has_resource::<A>(world) {
26 return None;
27 }
28
29 Some(Res {
30 data: resources.get_resource(world),
31 })
32 }
33}
34
35impl<'a, A, B> Dependencies<'a> for (Res<'a, A>, Res<'a, B>)
36where
37 A: 'static + Send + Sync,
38 B: 'static + Send + Sync,
39{
40 fn try_gather(world: &'a hecs::World, resources: &'a Resources) -> Option<Self> {
41 if !resources.has_resource::<A>(world) || !resources.has_resource::<B>(world) {
42 return None;
43 }
44
45 Some((
46 Res {
47 data: resources.get_resource(world),
48 },
49 Res {
50 data: resources.get_resource(world),
51 },
52 ))
53 }
54}