| 1 |
--- |
| 2 |
title: "ComponentInfo no longer stores the component ID" |
| 3 |
pull_requests: [25774] |
| 4 |
--- |
| 5 |
|
| 6 |
`ComponentInfo::id()` has been removed, and `ComponentInfo` no longer stores the component ID. Component IDs are already used as keys by the collections that store `ComponentInfo` instances; if you need both values, retain the `ComponentId` when |
| 7 |
retrieving the `ComponentInfo` from the collection: |
| 8 |
|
| 9 |
```rust |
| 10 |
// 0.19 |
| 11 |
let info = components.get_info(component_id).unwrap(); |
| 12 |
let id = info.id(); |
| 13 |
|
| 14 |
// 0.20 |
| 15 |
let id = component_id; |
| 16 |
let info = components.get_info(id).unwrap(); |
| 17 |
``` |
| 18 |
|
| 19 |
`Components::iter_registered()`, `World::inspect_entity`, `World::iter_resources`, |
| 20 |
and `World::iter_resources_mut` now return iterators that include `ComponentId` |
| 21 |
alongside `&ComponentInfo`, to retain access to the component ID with the component |
| 22 |
info: |
| 23 |
|
| 24 |
```rust |
| 25 |
// 0.19 |
| 26 |
for info in components.iter_registered() { |
| 27 |
let id = info.id(); |
| 28 |
// ... |
| 29 |
} |
| 30 |
|
| 31 |
for info in world.inspect_entity(entity)? { |
| 32 |
let id = info.id(); |
| 33 |
// ... |
| 34 |
} |
| 35 |
|
| 36 |
for (info, ptr) in world.iter_resources() { |
| 37 |
let id = info.id(); |
| 38 |
// ... |
| 39 |
} |
| 40 |
|
| 41 |
for (info, ptr) in world.iter_resources_mut() { |
| 42 |
let id = info.id(); |
| 43 |
// ... |
| 44 |
} |
| 45 |
|
| 46 |
// 0.20 |
| 47 |
for (id, info) in components.iter_registered() { |
| 48 |
// ... |
| 49 |
} |
| 50 |
|
| 51 |
for (id, info) in world.inspect_entity(entity)? { |
| 52 |
// ... |
| 53 |
} |
| 54 |
|
| 55 |
for (id, info, ptr) in world.iter_resources() { |
| 56 |
// ... |
| 57 |
} |
| 58 |
|
| 59 |
for (id, info, ptr) in world.iter_resources_mut() { |
| 60 |
// ... |
| 61 |
} |
| 62 |
``` |