bevyengine / bevyengine/bevy

Make `Query<&T>` return `Ref<T>`

Open
#7,322 4 comments 0 reactions 0 assignees View on GitHub
A-ECS C-Usability X-Needs-SME
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

A potentially more controversial option is just to have `&T` return `Ref` instead. Though that might require some benchmarking to ensure there's no perf regression in doing so.

_Originally posted by @james7132 in https://github.com/bevyengine/bevy/issues/7306#issuecomment-1399322255_

> A nice thing about making &T return Ref is that it would make the ReadOnly assoc type on &mut T have an "obvious answer", with this PR it could realistically be &T or Ref. I think the only downside that Mut has that Ref would also have is the fact that you cant pattern match on it, the other issues (shoving mut everywhere and borrowck annoyances from disjoint borrows) dont apply to Ref which is cool.

Boxy's followup.

This would align us further with the behavior of `&mut`, and ensure that change detection behavior is always available to users.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.