bevy/crates/bevy_ecs/src/world
Eagster 5db67f35e4
Get names of queued components (#18451)
# Objective

#18173 allows components to be queued without being fully registered.
But much of bevy's debug logging contained
`components.get_name(id).unwrap()`. However, this panics when the id is
queued. This PR fixes this, allowing names to be retrieved for debugging
purposes, etc, even while they're still queued.

## Solution

We change `ComponentInfo::descriptor` to be `Arc<ComponentDescriptor>`
instead of not arc'd. This lets us pass the descriptor around (as a name
or otherwise) as needed. The alternative would require some form of
`MappedRwLockReadGuard`, which is unstable, and would be terribly
blocking. Putting it in an arc also signifies that it doesn't change,
which is a nice signal to users. This does mean there's an extra pointer
dereference, but I don't think that's an issue here, as almost all paths
that use this are for debugging purposes or one-time set ups.

## Testing

Existing tests.

## Migration Guide

`Components::get_name` now returns `Option<Cow<'_, str>` instead of
`Option<&str>`. This is because it now returns results for queued
components. If that behavior is not desired, or you know the component
is not queued, you can use
`components.get_info().map(ComponentInfo::name)` instead.

Similarly, `ScheduleGraph::conflicts_to_string` now returns `impl
Iterator<Item = (String, String, Vec<Cow<str>>)>` instead of `impl
Iterator<Item = (String, String, Vec<&str>)>`. Because `Cow<str>` derefs
to `&str`, most use cases can remain unchanged.

---------

Co-authored-by: Chris Russell <8494645+chescock@users.noreply.github.com>
2025-03-31 23:22:33 +00:00
..
command_queue.rs Harden proc macro path resolution and add integration tests. (#17330) 2025-02-09 19:45:45 +00:00
component_constants.rs Harden proc macro path resolution and add integration tests. (#17330) 2025-02-09 19:45:45 +00:00
deferred_world.rs reexport entity set collections in entity module (#18413) 2025-03-30 03:51:14 +00:00
entity_fetch.rs reexport entity set collections in entity module (#18413) 2025-03-30 03:51:14 +00:00
entity_ref.rs Rename EntityBorrow/TrustedEntityBorrow to ContainsEntity/EntityEquivalent (#18470) 2025-03-30 06:04:26 +00:00
error.rs FilteredResource returns a Result instead of a simple Option (#18265) 2025-03-17 18:54:13 +00:00
filtered_resource.rs FilteredResource returns a Result instead of a simple Option (#18265) 2025-03-17 18:54:13 +00:00
identifier.rs Create bevy_platform_support Crate (#17250) 2025-01-20 20:45:30 +00:00
mod.rs Get names of queued components (#18451) 2025-03-31 23:22:33 +00:00
reflect.rs Get names of queued components (#18451) 2025-03-31 23:22:33 +00:00
spawn_batch.rs Encapsulate cfg(feature = "track_location") in a type. (#17602) 2025-02-10 21:21:20 +00:00
unsafe_world_cell.rs Rename EntityBorrow/TrustedEntityBorrow to ContainsEntity/EntityEquivalent (#18470) 2025-03-30 06:04:26 +00:00