Skip to content

Commit eca3076

Browse files
committed
Bevy app docs (#3539)
# Objective Achieve 100% documentation coverage for bevy_app crate. See #3492 ## Solution - Add #![warn(missing_docs)] to crate root - Add doc comments to public items - Add doc comment to bevy_utils::define_label macro trait
1 parent 44f370a commit eca3076

File tree

8 files changed

+56
-7
lines changed

8 files changed

+56
-7
lines changed

crates/bevy_app/src/app.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ use std::fmt::Debug;
1414

1515
#[cfg(feature = "trace")]
1616
use bevy_utils::tracing::info_span;
17-
1817
bevy_utils::define_label!(AppLabel);
1918

2019
#[allow(clippy::needless_doctest_main)]
2120
/// Containers of app logic and data
2221
///
2322
/// Bundles together the necessary elements, like [`World`] and [`Schedule`], to create
2423
/// an ECS-based application. It also stores a pointer to a
25-
/// [runner function](App::set_runner), which by default executes the App schedule
26-
/// once. Apps are constructed with the builder pattern.
24+
/// [runner function](Self::set_runner). The runner is responsible for managing the application's
25+
/// event loop and applying the [`Schedule`] to the [`World`] to drive application logic.
26+
/// Apps are constructed with the builder pattern.
2727
///
2828
/// ## Example
2929
/// Here is a simple "Hello World" Bevy app:
@@ -42,12 +42,22 @@ bevy_utils::define_label!(AppLabel);
4242
/// }
4343
/// ```
4444
pub struct App {
45+
/// The main ECS [`World`] of the [`App`].
46+
/// This stores and provides access to all the main data of the application.
47+
/// The systems of the [`App`] will run using this [`World`].
48+
/// If additional separate [`World`]-[`Schedule`] pairs are needed, you can use [`sub_app`][App::add_sub_app]s.
4549
pub world: World,
50+
/// The [runner function](Self::set_runner) is primarily responsible for managing
51+
/// the application's event loop and advancing the [`Schedule`].
52+
/// Typically, it is not configured manually, but set by one of Bevy's built-in plugins.
53+
/// See `bevy::winit::WinitPlugin` and [`ScheduleRunnerPlugin`](crate::schedule_runner::ScheduleRunnerPlugin).
4654
pub runner: Box<dyn Fn(App)>,
55+
/// A container of [`Stage`]s set to be run in a linear order.
4756
pub schedule: Schedule,
4857
sub_apps: HashMap<Box<dyn AppLabel>, SubApp>,
4958
}
5059

60+
/// Each [`SubApp`] has its own [`Schedule`] and [`World`], enabling a separation of concerns.
5161
struct SubApp {
5262
app: App,
5363
runner: Box<dyn Fn(&mut World, &mut App)>,
@@ -73,10 +83,15 @@ impl Default for App {
7383
}
7484

7585
impl App {
86+
/// Creates a new [`App`] with some default structure to enable core engine features.
87+
/// This is the preferred constructor for most use cases.
7688
pub fn new() -> App {
7789
App::default()
7890
}
7991

92+
/// Creates a new empty [`App`] with minimal default configuration.
93+
///
94+
/// This constructor should be used if you wish to provide a custom schedule, exit handling, cleanup, etc.
8095
pub fn empty() -> App {
8196
Self {
8297
world: Default::default(),
@@ -837,6 +852,9 @@ impl App {
837852
self
838853
}
839854

855+
/// Adds a "sub app" to this [`App`].
856+
///
857+
/// Sub apps are a largely experimental feature: each `SubApp` has its own [`Schedule`] and [`World`].
840858
pub fn add_sub_app(
841859
&mut self,
842860
label: impl AppLabel,

crates/bevy_app/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![warn(missing_docs)]
12
//! This crate is about everything concerning the highest-level, application layer of a Bevy
23
//! app.
34
@@ -16,6 +17,7 @@ pub use plugin::*;
1617
pub use plugin_group::*;
1718
pub use schedule_runner::*;
1819

20+
#[allow(missing_docs)]
1921
pub mod prelude {
2022
#[doc(hidden)]
2123
pub use crate::{app::App, CoreStage, DynamicPlugin, Plugin, PluginGroup, StartupStage};

crates/bevy_app/src/plugin.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ use std::any::Any;
66
/// Plugins configure an [`App`](crate::App). When an [`App`](crate::App) registers
77
/// a plugin, the plugin's [`Plugin::build`] function is run.
88
pub trait Plugin: Any + Send + Sync {
9+
/// Configures the [`App`] to which this plugin is added.
910
fn build(&self, app: &mut App);
11+
/// Configures a name for the [`Plugin`]. Primarily for debugging.
1012
fn name(&self) -> &str {
1113
std::any::type_name::<Self>()
1214
}
1315
}
1416

17+
/// Type representing an unsafe function that returns a mutable pointer to a [`Plugin`].
18+
/// Used for dynamically loading plugins. See bevy_dynamic_plugin/src/loader.rs#dynamically_load_plugin
1519
pub type CreatePlugin = unsafe fn() -> *mut dyn Plugin;

crates/bevy_app/src/plugin_group.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ use crate::{App, Plugin};
22
use bevy_utils::{tracing::debug, HashMap};
33
use std::any::TypeId;
44

5+
/// Combines multiple [`Plugin`]s into a single unit.
56
pub trait PluginGroup {
7+
/// Configures the [`Plugin`]s that are to be added.
68
fn build(&mut self, group: &mut PluginGroupBuilder);
79
}
810

@@ -11,13 +13,17 @@ struct PluginEntry {
1113
enabled: bool,
1214
}
1315

16+
/// Facilitates the creation and configuration of a [`PluginGroup`].
17+
/// Provides a build ordering to ensure that [`Plugin`]s which produce/require a resource
18+
/// are built before/after dependent/depending [`Plugin`]s.
1419
#[derive(Default)]
1520
pub struct PluginGroupBuilder {
1621
plugins: HashMap<TypeId, PluginEntry>,
1722
order: Vec<TypeId>,
1823
}
1924

2025
impl PluginGroupBuilder {
26+
/// Appends a [`Plugin`] to the [`PluginGroupBuilder`].
2127
pub fn add<T: Plugin>(&mut self, plugin: T) -> &mut Self {
2228
self.order.push(TypeId::of::<T>());
2329
self.plugins.insert(
@@ -30,6 +36,7 @@ impl PluginGroupBuilder {
3036
self
3137
}
3238

39+
/// Configures a [`Plugin`] to be built before another plugin.
3340
pub fn add_before<Target: Plugin, T: Plugin>(&mut self, plugin: T) -> &mut Self {
3441
let target_index = self
3542
.order
@@ -54,6 +61,7 @@ impl PluginGroupBuilder {
5461
self
5562
}
5663

64+
/// Configures a [`Plugin`] to be built after another plugin.
5765
pub fn add_after<Target: Plugin, T: Plugin>(&mut self, plugin: T) -> &mut Self {
5866
let target_index = self
5967
.order
@@ -78,6 +86,10 @@ impl PluginGroupBuilder {
7886
self
7987
}
8088

89+
/// Enables a [`Plugin`]
90+
///
91+
/// [`Plugin`]s within a [`PluginGroup`] are enabled by default. This function is used to
92+
/// opt back in to a [`Plugin`] after [disabling](Self::disable) it.
8193
pub fn enable<T: Plugin>(&mut self) -> &mut Self {
8294
let mut plugin_entry = self
8395
.plugins
@@ -87,6 +99,7 @@ impl PluginGroupBuilder {
8799
self
88100
}
89101

102+
/// Disables a [`Plugin`], preventing it from being added to the `App` with the rest of the [`PluginGroup`].
90103
pub fn disable<T: Plugin>(&mut self) -> &mut Self {
91104
let mut plugin_entry = self
92105
.plugins
@@ -96,6 +109,7 @@ impl PluginGroupBuilder {
96109
self
97110
}
98111

112+
/// Consumes the [`PluginGroupBuilder`] and [builds](Plugin::build) the contained [`Plugin`]s.
99113
pub fn finish(self, app: &mut App) {
100114
for ty in self.order.iter() {
101115
if let Some(entry) = self.plugins.get(ty) {

crates/bevy_app/src/schedule_runner.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ use std::{cell::RefCell, rc::Rc};
1111
#[cfg(target_arch = "wasm32")]
1212
use wasm_bindgen::{prelude::*, JsCast};
1313

14-
/// Determines the method used to run an [App]'s `Schedule`
14+
/// Determines the method used to run an [App]'s [`Schedule`](bevy_ecs::schedule::Schedule).
1515
#[derive(Copy, Clone, Debug)]
1616
pub enum RunMode {
17-
Loop { wait: Option<Duration> },
17+
/// Indicates that the [`App`]'s schedule should run repeatedly.
18+
Loop {
19+
/// Minimum duration to wait after a schedule has completed before repeating.
20+
/// A value of [`None`] will not wait.
21+
wait: Option<Duration>,
22+
},
23+
/// Indicates that the [`App`]'s schedule should run only once.
1824
Once,
1925
}
2026

@@ -24,18 +30,22 @@ impl Default for RunMode {
2430
}
2531
}
2632

33+
/// Configuration information for [`ScheduleRunnerPlugin`].
2734
#[derive(Copy, Clone, Default)]
2835
pub struct ScheduleRunnerSettings {
36+
/// Determines whether the [`Schedule`](bevy_ecs::schedule::Schedule) is run once or repeatedly.
2937
pub run_mode: RunMode,
3038
}
3139

3240
impl ScheduleRunnerSettings {
41+
/// [`RunMode::Once`]
3342
pub fn run_once() -> Self {
3443
ScheduleRunnerSettings {
3544
run_mode: RunMode::Once,
3645
}
3746
}
3847

48+
/// [`RunMode::Loop`]
3949
pub fn run_loop(wait_duration: Duration) -> Self {
4050
ScheduleRunnerSettings {
4151
run_mode: RunMode::Loop {

crates/bevy_dynamic_plugin/src/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use libloading::{Library, Symbol};
22

33
use bevy_app::{App, CreatePlugin, Plugin};
44

5-
/// Dynamically links a plugin a the given path. The plugin must export a function with the
5+
/// Dynamically links a plugin at the given path. The plugin must export a function with the
66
/// [`CreatePlugin`] signature named `_bevy_create_plugin`.
77
///
88
/// # Safety

crates/bevy_utils/src/label.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ where
5858
#[macro_export]
5959
macro_rules! define_label {
6060
($label_trait_name:ident) => {
61+
/// Defines a set of strongly-typed labels for a class of objects
6162
pub trait $label_trait_name:
6263
::bevy_utils::label::DynHash + ::std::fmt::Debug + Send + Sync + 'static
6364
{

examples/asset/custom_asset_io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn main() {
8080
// `CorePlugin' and `AssetPlugin`. It needs to be after the
8181
// CorePlugin, so that the IO task pool has already been constructed.
8282
// And it must be before the `AssetPlugin` so that the asset plugin
83-
// doesn't create another instance of an assert server. In general,
83+
// doesn't create another instance of an asset server. In general,
8484
// the AssetPlugin should still run so that other aspects of the
8585
// asset system are initialized correctly.
8686
group.add_before::<bevy::asset::AssetPlugin, _>(CustomAssetIoPlugin)

0 commit comments

Comments
 (0)