pub struct SubApp {
pub update_schedule: Option<Interned<dyn ScheduleLabel>>,
/* 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<Interned<dyn ScheduleLabel>>
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 SubApp
pub fn set_extract<F>(&mut self, extract: F) -> &mut SubApp
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>(&mut self, resource: R) -> &mut SubAppwhere
R: Resource,
pub fn insert_resource<R>(&mut self, resource: R) -> &mut SubAppwhere
R: Resource,
See App::insert_resource
.
sourcepub fn init_resource<R>(&mut self) -> &mut SubApp
pub fn init_resource<R>(&mut self) -> &mut SubApp
See App::init_resource
.
sourcepub fn add_systems<M>(
&mut self,
schedule: impl ScheduleLabel,
systems: impl IntoSystemConfigs<M>,
) -> &mut SubApp
pub fn add_systems<M>( &mut self, schedule: impl ScheduleLabel, systems: impl IntoSystemConfigs<M>, ) -> &mut SubApp
See App::add_systems
.
sourcepub fn register_system<I, O, M>(
&mut self,
system: impl IntoSystem<I, O, M> + 'static,
) -> SystemId<I, O>where
I: SystemInput + 'static,
O: 'static,
pub fn register_system<I, O, M>(
&mut self,
system: impl IntoSystem<I, O, M> + 'static,
) -> SystemId<I, O>where
I: SystemInput + 'static,
O: 'static,
See App::register_system
.
sourcepub fn configure_sets(
&mut self,
schedule: impl ScheduleLabel,
sets: impl IntoSystemSetConfigs,
) -> &mut SubApp
pub fn configure_sets( &mut self, schedule: impl ScheduleLabel, sets: impl IntoSystemSetConfigs, ) -> &mut SubApp
See App::configure_sets
.
sourcepub fn add_schedule(&mut self, schedule: Schedule) -> &mut SubApp
pub fn add_schedule(&mut self, schedule: Schedule) -> &mut SubApp
See App::add_schedule
.
sourcepub fn init_schedule(&mut self, label: impl ScheduleLabel) -> &mut SubApp
pub fn init_schedule(&mut self, label: impl ScheduleLabel) -> &mut SubApp
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 SubApp
pub fn edit_schedule( &mut self, label: impl ScheduleLabel, f: impl FnMut(&mut Schedule), ) -> &mut SubApp
See App::edit_schedule
.
sourcepub fn configure_schedules(
&mut self,
schedule_build_settings: ScheduleBuildSettings,
) -> &mut SubApp
pub fn configure_schedules( &mut self, schedule_build_settings: ScheduleBuildSettings, ) -> &mut SubApp
sourcepub fn allow_ambiguous_component<T>(&mut self) -> &mut SubAppwhere
T: Component,
pub fn allow_ambiguous_component<T>(&mut self) -> &mut SubAppwhere
T: Component,
sourcepub fn allow_ambiguous_resource<T>(&mut self) -> &mut SubAppwhere
T: Resource,
pub fn allow_ambiguous_resource<T>(&mut self) -> &mut SubAppwhere
T: Resource,
sourcepub fn ignore_ambiguity<M1, M2, S1, S2>(
&mut self,
schedule: impl ScheduleLabel,
a: S1,
b: S2,
) -> &mut SubAppwhere
S1: IntoSystemSet<M1>,
S2: IntoSystemSet<M2>,
pub fn ignore_ambiguity<M1, M2, S1, S2>(
&mut self,
schedule: impl ScheduleLabel,
a: S1,
b: S2,
) -> &mut SubAppwhere
S1: IntoSystemSet<M1>,
S2: IntoSystemSet<M2>,
sourcepub fn add_event<T>(&mut self) -> &mut SubAppwhere
T: Event,
pub fn add_event<T>(&mut self) -> &mut SubAppwhere
T: Event,
See App::add_event
.
sourcepub fn add_plugins<M>(&mut self, plugins: impl Plugins<M>) -> &mut SubApp
pub fn add_plugins<M>(&mut self, plugins: impl Plugins<M>) -> &mut SubApp
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>(&mut self) -> &mut SubAppwhere
T: GetTypeRegistration,
pub fn register_type<T>(&mut self) -> &mut SubAppwhere
T: GetTypeRegistration,
See App::register_type
.
sourcepub fn register_type_data<T, D>(&mut self) -> &mut SubApp
pub fn register_type_data<T, D>(&mut self) -> &mut SubApp
Trait Implementations§
source§impl RegisterDiagnostic for SubApp
impl RegisterDiagnostic for SubApp
source§fn register_diagnostic(&mut self, diagnostic: Diagnostic) -> &mut SubApp
fn register_diagnostic(&mut self, diagnostic: Diagnostic) -> &mut SubApp
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
Creates Self
using default()
.
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more