async_ecs/world/
setup.rs

1use crate::resource::Resource;
2
3use super::World;
4
5pub trait SetupHandler<T>: Sized {
6    fn setup(world: &mut World);
7}
8
9pub struct DefaultSetupHandler;
10
11impl<T> SetupHandler<T> for DefaultSetupHandler
12where
13    T: Default + Resource,
14{
15    fn setup(world: &mut World) {
16        world.entry().or_insert_with(T::default);
17    }
18}
19
20/// A setup handler that simply does nothing and thus will cause a panic on
21/// fetching.
22///
23/// A typedef called `ReadExpect` exists, so you usually don't use this type
24/// directly.
25pub struct PanicHandler;
26
27impl<T> SetupHandler<T> for PanicHandler
28where
29    T: Resource,
30{
31    fn setup(_: &mut World) {}
32}