Skip to content

Commit

Permalink
Address documentation feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
GarettCooper committed Jun 22, 2022
1 parent df727b0 commit 4e7ba81
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
19 changes: 14 additions & 5 deletions crates/bevy_ecs/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,20 @@ impl ComponentInfo {
}
}

/// A [`ComponentId`] is an opaque value which uniquely identifies the type of
/// a [`Component`] within a [`World`](crate::world::World). Each time a new
/// [`Component`] type is registered within a [`World`](crate::world::World) using
/// [`World::init_component`](crate::world::World::init_component) or
/// A [`ComponentId`] is an semi-opaque value which uniquely identifies the type of
/// a [`Component`] within a [`World`](crate::world::World).
///
/// Each time a new [`Component`] type is registered within a [`World`](crate::world::World)
/// using [`World::init_component`](crate::world::World::init_component) or
/// [`World::init_component_with_descriptor`](crate::world::World::init_component_with_descriptor),
/// a corresponding [`ComponentId`] is created to track it.
///
/// While the distinction between [`ComponentId`] and [`TypeId`] may seem superficial, breaking them
/// in to two separate but related concepts allows Bevy components to exist outside of Rust's type system.
/// Each Rust type registered as a [`Component`] will have a corresponding [`ComponentId`], but additional
/// [`ComponentId`]s may exist in a [`World`](crate::world::World) to track components which cannot be
/// represented as Rust types for scripting or other advanced use-cases.
///
/// A [`ComponentId`] is tightly coupled to its parent [`World`](crate::world::World).
/// Attempting to use a [`ComponentId`] from one [`World`](crate::world::World) to access the metadata
/// of a [`Component`] in a different [`World`](crate::world::World) is undefined behaviour and should
Expand Down Expand Up @@ -364,7 +371,9 @@ impl Components {
}

/// Retrieves the [`ComponentId`] of the given [`Component`] type in
/// this [`Components`] instance. Returns [`None`] if the [`Component`] type has not
/// this [`Components`] instance.
///
/// Returns [`None`] if the [`Component`] type has not
/// yet been initialized using [`Components::init_component`].
/// ```rust
/// use bevy_ecs::prelude::*;
Expand Down
15 changes: 9 additions & 6 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ impl World {
}

/// Initializes a new Component type within this [`World`] and returns the
/// [`ComponentId`] assigned to it. [`World::init_component_with_descriptor`]
/// differs from [`World::init_component`] in that it uses a [`ComponentDescriptor`]
/// to initialize the new component type instead of statically available type information.
/// This enables the dynamic initialization of new component definitions at runtime
/// for advanced use cases.
/// [`ComponentId`] assigned to it.
///
/// [`World::init_component_with_descriptor`] differs from [`World::init_component`] in
/// that it uses a [`ComponentDescriptor`] to initialize the new component type instead
/// of statically available type information. This enables the dynamic initialization of
/// new component definitions at runtime for advanced use cases.
///
/// While [`World::init_component_with_descriptor`] is useful in type-erased contexts,
/// the standard [`World::init_component`] function should always be used instead
Expand All @@ -202,7 +203,9 @@ impl World {
}

/// Retrieves the [`ComponentId`] of the given [`Component`] type in
/// this [`World`]. Returns [`None`] if the [`Component`] type has not
/// this [`World`].
///
/// Returns [`None`] if the [`Component`] type has not
/// yet been initialized within the [`World`] using [`World::init_component`].
/// ```rust
/// use bevy_ecs::prelude::*;
Expand Down

0 comments on commit 4e7ba81

Please sign in to comment.