Assets<T> should have `get_many` / `get_many_mut` or equivalent functions
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Similar to `Query<...>`, the `Assets` collection type maps from asset IDs to underlying data (e.g. sounds, animations, meshes, textures, ...). Because of this, it is unsound to allow multiple calls to `.get_mut()` on an `Assets`, since the returned references could alias each other:
```rs
fn example(assets: &mut Assets, handle1: Handle
, handle2: Handle
) {
let image_data1: &mut Image = assets.get_mut(&handle1);
let image_data2: &mut Image = assets.get_mut(&handle2);
println!("{:?} {:?}", image_data1.clone(), image_data2.clone()); // borrow error: multiple mutable borrows of `assets`
}
```
The `Query` type has the `get_many_mut` methods to get around this limitation, allowing multiple `Entity`s to be looked up at once, with a dynamic check to prevent the same entity from being accessed multiple times.
`Assets` should have a similar `get_many_mut` method with a dynamic check, offering safe mutable access to multiple (distinct) assets at once.
(Other designs are possible, but currently it makes sense to align with `Query<...>`)
Contributor guide
Research direction
Start by reading the Assets API and the Query<...> get_many_mut implementation. Compare how each type handles lookup and duplicate access, then determine the API and dynamic checks needed for distinct asset IDs. Done means safe multi-asset mutable access with duplicate IDs rejected and behavior covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- game-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100