Document sub apps (#3403)
Documentation added to: - `App::add_sub_app` ( - `App::update` (mentions that sub apps are updated here) ### Future work - An example for `add_sub_app` would be good, but I wasn't able to come up with a simple one. - Since `SubApp` is private, maybe the concept of sub applications could be introduced in the `App` struct-level documentation.
This commit is contained in:
parent
f073b2d7f3
commit
7c22f92ce4
@ -103,6 +103,8 @@ impl App {
|
|||||||
|
|
||||||
/// Advances the execution of the [`Schedule`] by one cycle.
|
/// Advances the execution of the [`Schedule`] by one cycle.
|
||||||
///
|
///
|
||||||
|
/// This method also updates sub apps. See [`add_sub_app`](Self::add_sub_app) for more details.
|
||||||
|
///
|
||||||
/// See [`Schedule::run_once`] for more details.
|
/// See [`Schedule::run_once`] for more details.
|
||||||
pub fn update(&mut self) {
|
pub fn update(&mut self) {
|
||||||
#[cfg(feature = "trace")]
|
#[cfg(feature = "trace")]
|
||||||
@ -852,20 +854,22 @@ impl App {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a "sub app" to this [`App`].
|
/// Adds an `App` as a child of the current one.
|
||||||
///
|
///
|
||||||
/// Sub apps are a largely experimental feature: each `SubApp` has its own [`Schedule`] and [`World`].
|
/// The provided function `f` is called by the [`update`](Self::update) method. The `World`
|
||||||
|
/// parameter represents the main app world, while the `App` parameter is just a mutable
|
||||||
|
/// reference to the sub app itself.
|
||||||
pub fn add_sub_app(
|
pub fn add_sub_app(
|
||||||
&mut self,
|
&mut self,
|
||||||
label: impl AppLabel,
|
label: impl AppLabel,
|
||||||
app: App,
|
app: App,
|
||||||
f: impl Fn(&mut World, &mut App) + 'static,
|
sub_app_runner: impl Fn(&mut World, &mut App) + 'static,
|
||||||
) -> &mut Self {
|
) -> &mut Self {
|
||||||
self.sub_apps.insert(
|
self.sub_apps.insert(
|
||||||
Box::new(label),
|
Box::new(label),
|
||||||
SubApp {
|
SubApp {
|
||||||
app,
|
app,
|
||||||
runner: Box::new(f),
|
runner: Box::new(sub_app_runner),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
self
|
self
|
||||||
|
Loading…
Reference in New Issue
Block a user