bevyengine / bevyengine/bevy

Add `World::resource_scope_by_id`

Open
#13,466 8 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Usability D-Straightforward S-Ready-For-Implementation X-Uncontroversial
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?

I working on https://github.com/projectharmonia/bevy_replicon and we do a lot of type erasure internally for perfomance and a nice API.

Sometimes I need to access a resource mutably by ID and other resources just as reference. Since we don't have something like `World::resource_scope_by_id`, I do the inverse:
```rust
world.resource_scope(|world, registry: Mut| {
world.resource_scope(|world, entity_map: Mut| {
world.resource_scope(|world, server_events: Mut| {
});
});
});
```

## What solution would you like?

But it would be nicer to do it like this:
```rust
world.resource_scope_by_id(id, |world, resource| {
let mut registry = world.resource::();
let mut entity_map = world.resource::();
let mut server_events = world.resource::();
// ...
});
```

Contributor guide

Open the contributing guide

Research direction

Start from World::resource_scope and the resource access APIs it uses. Compare the requested resource_scope_by_id callback and ID-based mutable access with the existing typed resource_scope behavior. Done means the API supports one resource selected by ID while allowing other resources to be accessed in the callback, with coverage for the intended borrowing behavior.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.