2024-07-15 13:39:41 +00:00
|
|
|
//! A trait for components that let you traverse the ECS.
|
|
|
|
|
2024-09-23 18:08:36 +00:00
|
|
|
use crate::{entity::Entity, query::ReadOnlyQueryData};
|
2024-07-15 13:39:41 +00:00
|
|
|
|
|
|
|
/// A component that can point to another entity, and which can be used to define a path through the ECS.
|
|
|
|
///
|
2024-09-23 18:08:36 +00:00
|
|
|
/// Traversals are used to [specify the direction] of [event propagation] in [observers].
|
|
|
|
/// The default query is `()`.
|
2024-07-15 13:39:41 +00:00
|
|
|
///
|
|
|
|
/// Infinite loops are possible, and are not checked for. While looping can be desirable in some contexts
|
|
|
|
/// (for example, an observer that triggers itself multiple times before stopping), following an infinite
|
|
|
|
/// traversal loop without an eventual exit will can your application to hang. Each implementer of `Traversal`
|
|
|
|
/// for documenting possible looping behavior, and consumers of those implementations are responsible for
|
|
|
|
/// avoiding infinite loops in their code.
|
|
|
|
///
|
|
|
|
/// [specify the direction]: crate::event::Event::Traversal
|
|
|
|
/// [event propagation]: crate::observer::Trigger::propagate
|
|
|
|
/// [observers]: crate::observer::Observer
|
2024-09-23 18:08:36 +00:00
|
|
|
pub trait Traversal: ReadOnlyQueryData {
|
2024-07-15 13:39:41 +00:00
|
|
|
/// Returns the next entity to visit.
|
2024-09-23 18:08:36 +00:00
|
|
|
fn traverse(item: Self::Item<'_>) -> Option<Entity>;
|
2024-07-15 13:39:41 +00:00
|
|
|
}
|
|
|
|
|
2024-09-23 18:08:36 +00:00
|
|
|
impl Traversal for () {
|
|
|
|
fn traverse(_: Self::Item<'_>) -> Option<Entity> {
|
2024-07-15 13:39:41 +00:00
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|