bevy_ecs/system/
schedule_system.rs

1use alloc::{borrow::Cow, vec::Vec};
2
3use crate::{
4    archetype::ArchetypeComponentId,
5    component::{ComponentId, Tick},
6    error::Result,
7    query::Access,
8    system::{input::SystemIn, BoxedSystem, System},
9    world::{unsafe_world_cell::UnsafeWorldCell, DeferredWorld, World},
10};
11
12use super::{IntoSystem, SystemParamValidationError};
13
14/// A wrapper system to change a system that returns `()` to return `Ok(())` to make it into a [`ScheduleSystem`]
15pub struct InfallibleSystemWrapper<S: System<In = ()>>(S);
16
17impl<S: System<In = ()>> InfallibleSystemWrapper<S> {
18    /// Create a new `OkWrapperSystem`
19    pub fn new(system: S) -> Self {
20        Self(IntoSystem::into_system(system))
21    }
22}
23
24impl<S: System<In = ()>> System for InfallibleSystemWrapper<S> {
25    type In = ();
26    type Out = Result;
27
28    #[inline]
29    fn name(&self) -> Cow<'static, str> {
30        self.0.name()
31    }
32
33    fn type_id(&self) -> core::any::TypeId {
34        self.0.type_id()
35    }
36
37    #[inline]
38    fn component_access(&self) -> &Access<ComponentId> {
39        self.0.component_access()
40    }
41
42    #[inline]
43    fn archetype_component_access(&self) -> &Access<ArchetypeComponentId> {
44        self.0.archetype_component_access()
45    }
46
47    #[inline]
48    fn is_send(&self) -> bool {
49        self.0.is_send()
50    }
51
52    #[inline]
53    fn is_exclusive(&self) -> bool {
54        self.0.is_exclusive()
55    }
56
57    #[inline]
58    fn has_deferred(&self) -> bool {
59        self.0.has_deferred()
60    }
61
62    #[inline]
63    unsafe fn run_unsafe(
64        &mut self,
65        input: SystemIn<'_, Self>,
66        world: UnsafeWorldCell,
67    ) -> Self::Out {
68        self.0.run_unsafe(input, world);
69        Ok(())
70    }
71
72    #[inline]
73    fn apply_deferred(&mut self, world: &mut World) {
74        self.0.apply_deferred(world);
75    }
76
77    #[inline]
78    fn queue_deferred(&mut self, world: DeferredWorld) {
79        self.0.queue_deferred(world);
80    }
81
82    #[inline]
83    unsafe fn validate_param_unsafe(
84        &mut self,
85        world: UnsafeWorldCell,
86    ) -> Result<(), SystemParamValidationError> {
87        self.0.validate_param_unsafe(world)
88    }
89
90    #[inline]
91    fn initialize(&mut self, world: &mut World) {
92        self.0.initialize(world);
93    }
94
95    #[inline]
96    fn update_archetype_component_access(&mut self, world: UnsafeWorldCell) {
97        self.0.update_archetype_component_access(world);
98    }
99
100    #[inline]
101    fn check_change_tick(&mut self, change_tick: Tick) {
102        self.0.check_change_tick(change_tick);
103    }
104
105    #[inline]
106    fn get_last_run(&self) -> Tick {
107        self.0.get_last_run()
108    }
109
110    #[inline]
111    fn set_last_run(&mut self, last_run: Tick) {
112        self.0.set_last_run(last_run);
113    }
114
115    fn default_system_sets(&self) -> Vec<crate::schedule::InternedSystemSet> {
116        self.0.default_system_sets()
117    }
118}
119
120/// Type alias for a `BoxedSystem` that a `Schedule` can store.
121pub type ScheduleSystem = BoxedSystem<(), Result>;