[Merged by Bors] - Add component_id function to World and Components#5066
[Merged by Bors] - Add component_id function to World and Components#5066GarettCooper wants to merge 6 commits intobevyengine:mainfrom
Conversation
684e166 to
df727b0
Compare
| /// 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.
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.
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.
alice-i-cecile
left a comment
There was a problem hiding this comment.
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
Nilirad
left a comment
There was a problem hiding this comment.
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
Nilirad
left a comment
There was a problem hiding this comment.
Much better 😁
I added some more nits that I probably didn't catch in the first review pass. I also added redundant link removal.
Nilirad
left a comment
There was a problem hiding this comment.
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
ComponentIdinstance corresponding to aComponent.ComponentIdfor a givenComponenttype #5060.Solution
component_id::<T: Component>(&self)function to bothWorldandComponentsto retrieve theComponentIdassociated withTfrom a immutable reference.Changelog
World::component_id::<C>()andComponents::component_id::<C>()to retrieve aComponent's correspondingComponentIdif it exists.