-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
change return type of World::resource_ref
to Ref
#15263
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
change return type of World::resource_ref
to Ref
#15263
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only allow conversions to Ref
from Res
, not the other way around. Ditto for ResMut
and Mut
. Otherwise, it's possible to get a Ref
or Mut
from a Query
and then treat it as a resource, which is very confusing.
You would only be able to convert Ref to Res if the inner value is a resource. Although I would like to replace I'm okay with removing it altogether though, but I do remember needing to get a Res from a world (this was my motivation for adding Anyways, I don't see a problem with potentially getting Res from a Ref in a query since the component need to also be a resource for that to be possible, and you cant really so anything weird/funky with it anyways. What do you think? (Sorry for the ramble, I'm on my phone) |
Nvm, Res doesn't have a new method |
Ah, I see: the trait bound on the From impl will enforce that. Hmm. Okay, I don't hate exposing this then. |
Great, thoughts on A new constructor would mean you can't do |
No strong feelings. IMO let's stick with the From impls for consistency. |
This seems like the opposite of what was requested in the linked issue?
This is true1. Functions that aren't systems should only be taking or providing I don't think we should encourage using them interchangeably even if Footnotes
|
Yeah, I once needed to get a |
resource_ref
to Ref
resource_ref
to Ref
World::resource_ref
to Ref
@alice-i-cecile are you sure this is controversial now? I removed the conversion from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason why not expose this method, can reduce confusion over the types Res and Ref.
It looks like your PR is a breaking change, but you didn't provide a migration guide. Could you add some context on what users should update when this change get released in a new version of Bevy? |
This broke my code and there is nothing in the migration guide... what do i do. now im blocked on my project and nobody can help me |
Objective
Closes #11825
Solution
Change return type of
get_resource_ref
andresource_ref
fromRes
toRef
and implementFrom Res<T> for Ref<T>
.Migration guide
Previously
World::get_resource_ref::<T>
andWorld::resource_ref::<T>
would return aRes<T>
which was inconsistent with the rest of theWorld
API (notablyresource_scope
). This has been fixed and the methods now returnRef<T>
.This means it is no longer possible to get
Res<T>
fromWorld
. If you were relying on this, you should try usingRef<T>
instead since it has the same functionality.Before
After