pub struct SubApp {
pub update_schedule: Option<InternedScheduleLabel>,
/* private fields */
}
Expand description
A secondary application with its own World
. These can run independently of each other.
These are useful for situations where certain processes (e.g. a render thread) need to be kept separate from the main application.
§Example
#[derive(Resource, Default)]
struct Val(pub i32);
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, AppLabel)]
struct ExampleApp;
// Create an app with a certain resource.
let mut app = App::new();
app.insert_resource(Val(10));
// Create a sub-app with the same resource and a single schedule.
let mut sub_app = SubApp::new();
sub_app.insert_resource(Val(100));
// Setup an extract function to copy the resource's value in the main world.
sub_app.set_extract(|main_world, sub_world| {
sub_world.resource_mut::<Val>().0 = main_world.resource::<Val>().0;
});
// Schedule a system that will verify extraction is working.
sub_app.add_systems(Main, |counter: Res<Val>| {
// The value will be copied during extraction, so we should see 10 instead of 100.
assert_eq!(counter.0, 10);
});
// Add the sub-app to the main app.
app.insert_sub_app(ExampleApp, sub_app);
// Update the application once (using the default runner).
app.run();
Fields§
§update_schedule: Option<InternedScheduleLabel>
The schedule that will be run by update
.
Implementations§
source§impl SubApp
impl SubApp
sourcepub fn run_default_schedule(&mut self)
pub fn run_default_schedule(&mut self)
Runs the default schedule.
Does not clear internal trackers used for change detection.
sourcepub fn extract(&mut self, world: &mut World)
pub fn extract(&mut self, world: &mut World)
Extracts data from world
into the app’s world using the registered extract method.
Note: There is no default extract method. Calling extract
does nothing if
set_extract
has not been called.
sourcepub fn set_extract<F>(&mut self, extract: F) -> &mut Self
pub fn set_extract<F>(&mut self, extract: F) -> &mut Self
Sets the method that will be called by extract
.
The first argument is the World
to extract data from, the second argument is the app World
.
sourcepub fn insert_resource<R: Resource>(&mut self, resource: R) -> &mut Self
pub fn insert_resource<R: Resource>(&mut self, resource: R) -> &mut Self
See App::insert_resource
.
sourcepub fn init_resource<R: Resource + FromWorld>(&mut self) -> &mut Self
pub fn init_resource<R: Resource + FromWorld>(&mut self) -> &mut Self
See App::init_resource
.
sourcepub fn add_systems<M>(
&mut self,
schedule: impl ScheduleLabel,
systems: impl IntoSystemConfigs<M>
) -> &mut Self
pub fn add_systems<M>( &mut self, schedule: impl ScheduleLabel, systems: impl IntoSystemConfigs<M> ) -> &mut Self
See App::add_systems
.
sourcepub fn register_system<I: 'static, O: 'static, M, S: IntoSystem<I, O, M> + 'static>(
&mut self,
system: S
) -> SystemId<I, O>
pub fn register_system<I: 'static, O: 'static, M, S: IntoSystem<I, O, M> + 'static>( &mut self, system: S ) -> SystemId<I, O>
See App::register_system
.
sourcepub fn configure_sets(
&mut self,
schedule: impl ScheduleLabel,
sets: impl IntoSystemSetConfigs
) -> &mut Self
pub fn configure_sets( &mut self, schedule: impl ScheduleLabel, sets: impl IntoSystemSetConfigs ) -> &mut Self
See App::configure_sets
.
sourcepub fn add_schedule(&mut self, schedule: Schedule) -> &mut Self
pub fn add_schedule(&mut self, schedule: Schedule) -> &mut Self
See App::add_schedule
.
sourcepub fn init_schedule(&mut self, label: impl ScheduleLabel) -> &mut Self
pub fn init_schedule(&mut self, label: impl ScheduleLabel) -> &mut Self
See App::init_schedule
.
sourcepub fn get_schedule(&self, label: impl ScheduleLabel) -> Option<&Schedule>
pub fn get_schedule(&self, label: impl ScheduleLabel) -> Option<&Schedule>
See App::get_schedule
.
sourcepub fn get_schedule_mut(
&mut self,
label: impl ScheduleLabel
) -> Option<&mut Schedule>
pub fn get_schedule_mut( &mut self, label: impl ScheduleLabel ) -> Option<&mut Schedule>
sourcepub fn edit_schedule(
&mut self,
label: impl ScheduleLabel,
f: impl FnMut(&mut Schedule)
) -> &mut Self
pub fn edit_schedule( &mut self, label: impl ScheduleLabel, f: impl FnMut(&mut Schedule) ) -> &mut Self
See App::edit_schedule
.
sourcepub fn configure_schedules(
&mut self,
schedule_build_settings: ScheduleBuildSettings
) -> &mut Self
pub fn configure_schedules( &mut self, schedule_build_settings: ScheduleBuildSettings ) -> &mut Self
sourcepub fn allow_ambiguous_component<T: Component>(&mut self) -> &mut Self
pub fn allow_ambiguous_component<T: Component>(&mut self) -> &mut Self
sourcepub fn allow_ambiguous_resource<T: Resource>(&mut self) -> &mut Self
pub fn allow_ambiguous_resource<T: Resource>(&mut self) -> &mut Self
sourcepub fn ignore_ambiguity<M1, M2, S1, S2>(
&mut self,
schedule: impl ScheduleLabel,
a: S1,
b: S2
) -> &mut Selfwhere
S1: IntoSystemSet<M1>,
S2: IntoSystemSet<M2>,
pub fn ignore_ambiguity<M1, M2, S1, S2>(
&mut self,
schedule: impl ScheduleLabel,
a: S1,
b: S2
) -> &mut Selfwhere
S1: IntoSystemSet<M1>,
S2: IntoSystemSet<M2>,
sourcepub fn add_event<T>(&mut self) -> &mut Selfwhere
T: Event,
pub fn add_event<T>(&mut self) -> &mut Selfwhere
T: Event,
See App::add_event
.
sourcepub fn add_plugins<M>(&mut self, plugins: impl Plugins<M>) -> &mut Self
pub fn add_plugins<M>(&mut self, plugins: impl Plugins<M>) -> &mut Self
See App::add_plugins
.
sourcepub fn is_plugin_added<T>(&self) -> boolwhere
T: Plugin,
pub fn is_plugin_added<T>(&self) -> boolwhere
T: Plugin,
See App::is_plugin_added
.
sourcepub fn get_added_plugins<T>(&self) -> Vec<&T>where
T: Plugin,
pub fn get_added_plugins<T>(&self) -> Vec<&T>where
T: Plugin,
sourcepub fn plugins_state(&mut self) -> PluginsState
pub fn plugins_state(&mut self) -> PluginsState
Return the state of plugins.
sourcepub fn finish(&mut self)
pub fn finish(&mut self)
Runs Plugin::finish
for each plugin.
sourcepub fn cleanup(&mut self)
pub fn cleanup(&mut self)
Runs Plugin::cleanup
for each plugin.
sourcepub fn register_type<T: GetTypeRegistration>(&mut self) -> &mut Self
pub fn register_type<T: GetTypeRegistration>(&mut self) -> &mut Self
See App::register_type
.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SubApp
impl !RefUnwindSafe for SubApp
impl Send for SubApp
impl !Sync for SubApp
impl Unpin for SubApp
impl !UnwindSafe for SubApp
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.source§impl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
source§fn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given World
.