bevy_ecs/system/commands/ folder docs pass (#18639)

- Lots of nits, formatting, and rephrasing, with the goal of making
things more consistent.
- Fix outdated error handler explanation in `Commands` and
`EntityCommands` docs.
- Expand docs for system-related commands.
- Remove panic notes if the command only panics with the default error
handler.
- Update error handling notes for `try_` variants.
- Hide `prelude` import in most doctest examples, unless the example
uses something that people might not realize is in the prelude (like
`Name`).
- Remove a couple doctest examples that (in my opinion) didn't make
sense.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
This commit is contained in:
JaySpruce 2025-03-31 14:26:58 -05:00 committed by François Mockers
parent 831c57d8b1
commit 735c43390c
4 changed files with 435 additions and 511 deletions

View File

@ -1,5 +1,5 @@
//! This module contains the definition of the [`Command`] trait, as well as
//! blanket implementations of the trait for closures.
//! Contains the definition of the [`Command`] trait,
//! as well as the blanket implementation of the trait for closures.
//!
//! It also contains functions that return closures for use with
//! [`Commands`](crate::system::Commands).
@ -183,8 +183,10 @@ where
}
}
/// A [`Command`] that removes a system previously registered with
/// [`World::register_system_cached`].
/// A [`Command`] that removes a system previously registered with one of the following:
/// - [`Commands::run_system_cached`](crate::system::Commands::run_system_cached)
/// - [`World::run_system_cached`]
/// - [`World::register_system_cached`]
pub fn unregister_system_cached<I, O, M, S>(system: S) -> impl Command<Result>
where
I: SystemInput + Send + 'static,

View File

@ -1,5 +1,5 @@
//! This module contains the definition of the [`EntityCommand`] trait, as well as
//! blanket implementations of the trait for closures.
//! Contains the definition of the [`EntityCommand`] trait,
//! as well as the blanket implementation of the trait for closures.
//!
//! It also contains functions that return closures for use with
//! [`EntityCommands`](crate::system::EntityCommands).
@ -203,9 +203,10 @@ pub fn retain<T: Bundle>() -> impl EntityCommand {
///
/// # Note
///
/// This will also despawn any [`Children`](crate::hierarchy::Children) entities,
/// and any other [`RelationshipTarget`](crate::relationship::RelationshipTarget) that is configured to despawn descendants.
/// This results in "recursive despawn" behavior.
/// This will also despawn the entities in any [`RelationshipTarget`](crate::relationship::RelationshipTarget)
/// that is configured to despawn descendants.
///
/// For example, this will recursively despawn [`Children`](crate::hierarchy::Children).
#[track_caller]
pub fn despawn() -> impl EntityCommand {
let caller = MaybeLocation::caller();
@ -227,6 +228,7 @@ pub fn observe<E: Event, B: Bundle, M>(
}
/// An [`EntityCommand`] that sends a [`Trigger`](crate::observer::Trigger) targeting an entity.
///
/// This will run any [`Observer`](crate::observer::Observer) of the given [`Event`] watching the entity.
#[track_caller]
pub fn trigger(event: impl Event) -> impl EntityCommand {

File diff suppressed because it is too large Load Diff

View File

@ -20,9 +20,13 @@ struct ParallelCommandQueue {
/// [`Bundle`](crate::prelude::Bundle) type need to be spawned, consider using
/// [`Commands::spawn_batch`] for better performance.
///
/// Note: Because command application order will depend on how many threads are ran, non-commutative commands may result in non-deterministic results.
/// # Note
///
/// Because command application order will depend on how many threads are ran,
/// non-commutative commands may result in non-deterministic results.
///
/// # Example
///
/// Example:
/// ```
/// # use bevy_ecs::prelude::*;
/// # use bevy_tasks::ComputeTaskPool;