Skip to content

Commit 5ba438b

Browse files
Apply documentation suggestions from code review
Co-authored-by: Federico Rinaldi <gisquerin@gmail.com>
1 parent 34d5714 commit 5ba438b

3 files changed

Lines changed: 31 additions & 35 deletions

File tree

crates/bevy_ecs/src/component.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub struct Components {
377377
impl Components {
378378
/// Adds a new component type to [`Components`].
379379
///
380-
/// If the component type is already present, then simply return its [`ComponentId`].
380+
/// If the component type is already present, it simply returns its [`ComponentId`].
381381
#[inline]
382382
pub fn init_component<T: Component>(&mut self, storages: &mut Storages) -> ComponentId {
383383
let type_id = TypeId::of::<T>();

crates/bevy_ecs/src/world/archetype_invariants.rs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use bevy_utils::{tracing::warn, HashSet};
44

55
use crate::{component::ComponentId, prelude::Bundle, world::World};
66

7-
/// A rule about which [`Component`](crate::component::Component)s can coexist on entities
7+
/// A rule about which [`Component`](crate::component::Component)s can coexist on entities.
88
///
99
/// These rules must be true at all times for all entities in the [`World`].
1010
/// The generic [`Bundle`] type `B1` is always used in the `predicate`,
@@ -18,9 +18,6 @@ use crate::{component::ComponentId, prelude::Bundle, world::World};
1818
///
1919
/// Archetypes are only modified when a novel archetype (set of components) is seen for the first time;
2020
/// swapping between existing archetypes will not trigger these checks.
21-
///
22-
/// Note that this is converted to an [`UntypedArchetypeInvariant`] when added to a [`World`].
23-
/// This is to ensure compatibility between different invariants.
2421
#[derive(Clone, Debug, PartialEq)]
2522
pub struct ArchetypeInvariant<B1: Bundle, B2: Bundle = B1> {
2623
/// For all entities where the predicate is true
@@ -43,9 +40,9 @@ impl<B1: Bundle, B2: Bundle> ArchetypeInvariant<B1, B2> {
4340
}
4441

4542
impl<B: Bundle> ArchetypeInvariant<B, B> {
46-
/// This is a helper function for constructing common invariants.
47-
/// All components of the provided bundle require each other.
48-
/// In other words, if any one component of this bundle is present, then all of them must be.
43+
/// Creates an archetype invariant where all components of `B` require each other.
44+
///
45+
/// In other words, if any component of this bundle is present, then all of them must be.
4946
#[inline]
5047
pub fn full_bundle() -> Self {
5148
Self {
@@ -70,20 +67,20 @@ impl<B: Bundle> ArchetypeInvariant<B, B> {
7067
/// This is to ensure compatibility between different invariants.
7168
#[derive(Clone, Debug, PartialEq)]
7269
pub enum ArchetypeStatement<B: Bundle> {
73-
/// Evaluates to true if and only if the entity has all of the components present in the bundle `B`
70+
/// Evaluates to true if and only if the entity has all of the components present in the bundle `B`.
7471
AllOf(PhantomData<B>),
75-
/// The entity has at least one component in the bundle `B`, and may have all of them.
72+
/// The entity has at least one component in the bundle `B`.
7673
/// When using a single-component bundle, `AllOf` is preferred.
7774
AtLeastOneOf(PhantomData<B>),
7875
/// The entity has zero or one of the components in the bundle `B`, but no more.
79-
/// When using a single-component bundle, this is a tautology.
76+
/// When using a single-component bundle, this will always be true.
8077
AtMostOneOf(PhantomData<B>),
81-
/// The entity has none of the components in the bundle `B`
78+
/// The entity has none of the components in the bundle `B`.
8279
NoneOf(PhantomData<B>),
8380
}
8481

8582
impl<B: Bundle> ArchetypeStatement<B> {
86-
/// Erases the type information of this archetype statment.
83+
/// Erases the type information of this archetype statement.
8784
///
8885
/// Requires mutable world access, since the components might not have been added to the world yet.
8986
pub fn into_untyped(self, world: &mut World) -> UntypedArchetypeStatement {
@@ -105,25 +102,25 @@ impl<B: Bundle> ArchetypeStatement<B> {
105102
}
106103
}
107104

108-
/// Constructs a new [`ArchetypeStatement::AllOf`] variant for all components stored in the bundle `B`
105+
/// Constructs a new [`ArchetypeStatement::AllOf`] variant for all components stored in the bundle `B`.
109106
#[inline]
110107
pub const fn all_of() -> Self {
111108
ArchetypeStatement::AllOf(PhantomData)
112109
}
113110

114-
/// Constructs a new [`ArchetypeStatement::AtLeastOneOf`] variant for all components stored in the bundle `B`
111+
/// Constructs a new [`ArchetypeStatement::AtLeastOneOf`] variant for all components stored in the bundle `B`.
115112
#[inline]
116113
pub const fn at_least_one_of() -> Self {
117114
ArchetypeStatement::AtLeastOneOf(PhantomData)
118115
}
119116

120-
/// Constructs a new [`ArchetypeStatement::AtMostOneOf`] variant for all components stored in the bundle `B`
117+
/// Constructs a new [`ArchetypeStatement::AtMostOneOf`] variant for all components stored in the bundle `B`.
121118
#[inline]
122119
pub const fn at_most_one_of() -> Self {
123120
ArchetypeStatement::AtMostOneOf(PhantomData)
124121
}
125122

126-
/// Constructs a new [`ArchetypeStatement::NoneOf`] variant for all components stored in the bundle `B`
123+
/// Constructs a new [`ArchetypeStatement::NoneOf`] variant for all components stored in the bundle `B`.
127124
#[inline]
128125
pub const fn none_of() -> Self {
129126
ArchetypeStatement::NoneOf(PhantomData)
@@ -143,14 +140,14 @@ pub struct UntypedArchetypeInvariant {
143140
}
144141

145142
impl UntypedArchetypeInvariant {
146-
/// Assert that the provided iterator of [`ComponentId`]s obeys this archetype invariant
143+
/// Asserts that the provided iterator of [`ComponentId`]s obeys this archetype invariant.
147144
///
148145
/// `component_ids` is generally provided via the `components` field on [`Archetype`](crate::archetype::Archetype).
149146
/// When testing against multiple archetypes, [`ArchetypeInvariants::test_archetype`] is preferred,
150147
/// as it can more efficiently cache checks between archetypes.
151148
///
152149
/// # Panics
153-
/// Panics if the archetype invariant is violated
150+
/// Panics if the archetype invariant is violated.
154151
pub fn test_archetype(&self, component_ids_of_archetype: impl Iterator<Item = ComponentId>) {
155152
let component_ids_of_archetype: HashSet<ComponentId> = component_ids_of_archetype.collect();
156153

@@ -165,20 +162,21 @@ impl UntypedArchetypeInvariant {
165162
}
166163
}
167164

168-
/// A type-erased version of [`ArchetypeStatement`]
165+
/// A type-erased version of [`ArchetypeStatement`].
166+
///
169167
/// Intended to be used with dynamic components that cannot be represented with Rust types.
170168
/// Prefer [`ArchetypeStatement`] when possible.
171169
#[derive(Clone, Debug, PartialEq)]
172170
pub enum UntypedArchetypeStatement {
173-
/// Evaluates to true if and only if the entity has all of the components present in the set
171+
/// Evaluates to true if and only if the entity has all of the components present in the set.
174172
AllOf(HashSet<ComponentId>),
175173
/// The entity has at least one component in the set, and may have all of them.
176-
/// When using a single-component set, `AllOf` is preferred
174+
/// When using a single-component set, `AllOf` is preferred.
177175
AtLeastOneOf(HashSet<ComponentId>),
178176
/// The entity has zero or one of the components in the set, but no more.
179177
/// When using a single-component set, this is a tautology.
180178
AtMostOneOf(HashSet<ComponentId>),
181-
/// The entity has none of the components in the set
179+
/// The entity has none of the components in the set.
182180
NoneOf(HashSet<ComponentId>),
183181
}
184182

@@ -193,7 +191,7 @@ impl UntypedArchetypeStatement {
193191
}
194192
}
195193

196-
/// Test if this statement is true for the provided set of [`ComponentId`]s
194+
/// Test if this statement is true for the provided set of [`ComponentId`]s.
197195
pub fn test(&self, component_ids: &HashSet<ComponentId>) -> bool {
198196
match self {
199197
UntypedArchetypeStatement::AllOf(required_ids) => {
@@ -238,26 +236,27 @@ impl UntypedArchetypeStatement {
238236

239237
#[derive(Default)]
240238
pub struct ArchetypeInvariants {
241-
/// The list of invariants that must be upheld
239+
/// The list of invariants that must be upheld.
242240
raw_list: Vec<UntypedArchetypeInvariant>,
243241
}
244242

245243
impl ArchetypeInvariants {
246244
/// Adds a new [`ArchetypeInvariant`] to this set of archetype invariants.
247245
///
248246
/// Whenever a new archetype invariant is added, all existing archetypes are re-checked.
249-
/// This may include empty archetypes- archetypes that contain no entities.
247+
/// This may include empty archetypes: archetypes that contain no entities.
250248
#[inline]
251249
pub fn add(&mut self, archetype_invariant: UntypedArchetypeInvariant) {
252250
self.raw_list.push(archetype_invariant);
253251
}
254252

255-
/// Assert that the provided iterator of [`ComponentId`]s obeys all archetype invariants
253+
/// Asserts that the provided iterator of [`ComponentId`]s obeys all archetype invariants.
256254
///
257255
/// `component_ids` is generally provided via the `components` field on [`Archetype`](crate::archetype::Archetype).
258256
///
259257
/// # Panics
260-
/// Panics if any archetype invariant is violated
258+
///
259+
/// Panics if any archetype invariant is violated.
261260
pub fn test_archetype(&self, component_ids_of_archetype: impl Iterator<Item = ComponentId>) {
262261
let component_ids_of_archetype: HashSet<ComponentId> = component_ids_of_archetype.collect();
263262

crates/bevy_ecs/src/world/mod.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub mod archetype_invariants;
1+
mod archetype_invariants;
22
mod entity_ref;
33
mod spawn_batch;
44
mod world_cell;
@@ -7,10 +7,7 @@ pub use crate::change_detection::Mut;
77
pub use entity_ref::*;
88
pub use spawn_batch::*;
99
pub use world_cell::*;
10-
11-
use self::archetype_invariants::{
12-
ArchetypeInvariant, ArchetypeInvariants, UntypedArchetypeInvariant,
13-
};
10+
pub use archetype_invariants::*;
1411

1512
use crate::{
1613
archetype::{ArchetypeComponentId, ArchetypeComponentInfo, ArchetypeId, Archetypes},
@@ -159,7 +156,7 @@ impl World {
159156
&self.archetypes
160157
}
161158

162-
/// Retrieves this world's [`ArchetypeInvariants`] collection
159+
/// Retrieves this world's [`ArchetypeInvariants`] collection.
163160
#[inline]
164161
pub fn archetype_invariants(&self) -> &ArchetypeInvariants {
165162
&self.archetype_invariants
@@ -672,7 +669,7 @@ impl World {
672669
self.archetype_invariants.add(untyped_invariant);
673670
}
674671

675-
/// Inserts a new [`UntypedArchetypeInvariant`] to the world
672+
/// Inserts a new [`UntypedArchetypeInvariant`] to the world.
676673
///
677674
/// Whenever a new archetype invariant is added, all existing archetypes are re-checked.
678675
/// This may include empty archetypes- archetypes that contain no entities.

0 commit comments

Comments
 (0)