-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
World::resource_ref
should return Ref<T>
#11825
Comments
I'm on board with that as a design principle. However we should have a parallel method on Can you close out all of the conflicting issues and PRs? |
I have no problem with going in this direction. But to play devil's advocate, I'll say that maybe if the only way to get a change-detection-enabled reference to a resource in a system is through We don't have a choice on whether to use
I know when I was learning bevy I was confused on why some things were different inside of systems as opposed to outside of them (when interacting directly with the I don't think code duplication is a major concern because we can implement additional context: |
To reflect this idea in the code, struct Res<'w, T>(Ref<'w, T>);
struct ResMut<'w, T>(Mut<'w, T>); It will also help reduce code duplication by proxying the API calls. |
# Objective Closes #11825 ## Solution Change return type of `get_resource_ref` and `resource_ref` from `Res` to `Ref` and implement `From Res<T> for Ref<T>`.
What problem does this solve or what need does it fill?
World::resource_ref
currently returnsRes<T>
, which does not make sense asRes<T>
doesn't provide any functionality overRef<T>
. The only reason thatRes<T>
andResMut<T>
exist is that system params need to use the type to distinguish resources from other data. Otherwise,Res{Mut}<T>
do not need to exist, and thus we have always treatedRef<T>
andMut<T>
and as the change detection primitives.ResMut::map_unchanged
andResMut::reborrow
have always returnedMut<T>
to reflect this.I disagree with returning
Res<T>
here, as it encourages more use of this type. We should use types likeRes<T>
andResMut<T>
and little as possible, so we won't need to duplicate all change detection APIs for these types.What solution would you like?
World::resource_ref
should returnRef<T>
.What alternative(s) have you considered?
None
Additional context
#9926
#11776
#11776
#9940
The text was updated successfully, but these errors were encountered: