-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Merged by Bors] - Add component_id function to World and Components #5066
Conversation
684e166
to
df727b0
Compare
/// 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 | ||
/// not be attempted. | ||
#[derive(Debug, Copy, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)] | ||
pub struct ComponentId(usize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should consider talking a bit about the relationship with TypeId
here too.
Basically, for Rust types, there's a one-to-one mapping between TypeId
and ComponentId
. But non-Rust components can be used (well, only kind of so far), and these also get their own ComponentId
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a new section to explain the relationship. I'm not totally happy with the last sentence "Each Rust type ... or other advanced use cases" since it's pretty clunky, but after fiddling with it for a bit I couldn't come up with anything that wasn't quite a bit more verbose. Suggestions appreciated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work, these are really well written docs and the methods are simple and useful.
A few small pieces of doc feedback for you.
4e7ba81
to
ab8cfc4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, your descriptions are very nice overall.
I added some nits that helps significantly improve the form of the rendered docs.
Also, keep in mind that adding a link to the same item multiple times within the same item will lower the consulting experience (it looks like there are a lot of connections while actually there are a lot less).
You can view the rendered docs by yourself by using the following command, in case you didn't know:
cargo doc -p bevy_ecs --no-deps --open
Still great work anyway 😀
b560c74
to
ad5120e
Compare
ad5120e
to
25a6e3f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better 😁
I added some more nits that I probably didn't catch in the first review pass. I also added redundant link removal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a couple of suggestions about the style of unit struct declaration. Anyway, it looks good to me. 👍🏻
bors r+ |
# Objective - Simplify the process of obtaining a `ComponentId` instance corresponding to a `Component`. - Resolves #5060. ## Solution - Add a `component_id::<T: Component>(&self)` function to both `World` and `Components` to retrieve the `ComponentId` associated with `T` from a immutable reference. --- ## Changelog - Added `World::component_id::<C>()` and `Components::component_id::<C>()` to retrieve a `Component`'s corresponding `ComponentId` if it exists.
# Objective - Simplify the process of obtaining a `ComponentId` instance corresponding to a `Component`. - Resolves bevyengine#5060. ## Solution - Add a `component_id::<T: Component>(&self)` function to both `World` and `Components` to retrieve the `ComponentId` associated with `T` from a immutable reference. --- ## Changelog - Added `World::component_id::<C>()` and `Components::component_id::<C>()` to retrieve a `Component`'s corresponding `ComponentId` if it exists.
# Objective - Simplify the process of obtaining a `ComponentId` instance corresponding to a `Component`. - Resolves bevyengine#5060. ## Solution - Add a `component_id::<T: Component>(&self)` function to both `World` and `Components` to retrieve the `ComponentId` associated with `T` from a immutable reference. --- ## Changelog - Added `World::component_id::<C>()` and `Components::component_id::<C>()` to retrieve a `Component`'s corresponding `ComponentId` if it exists.
# Objective - Simplify the process of obtaining a `ComponentId` instance corresponding to a `Component`. - Resolves bevyengine#5060. ## Solution - Add a `component_id::<T: Component>(&self)` function to both `World` and `Components` to retrieve the `ComponentId` associated with `T` from a immutable reference. --- ## Changelog - Added `World::component_id::<C>()` and `Components::component_id::<C>()` to retrieve a `Component`'s corresponding `ComponentId` if it exists.
Objective
ComponentId
instance corresponding to aComponent
.ComponentId
for a givenComponent
type #5060.Solution
component_id::<T: Component>(&self)
function to bothWorld
andComponents
to retrieve theComponentId
associated withT
from a immutable reference.Changelog
World::component_id::<C>()
andComponents::component_id::<C>()
to retrieve aComponent
's correspondingComponentId
if it exists.