-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - Impl AsRef+AsMut for Res, ResMut, and Mut #2189
Conversation
Of particular note: this is likely to make sharing logic between components and resources easier. For example I would like to try to use this to create EventReaders that can be stored in both system and query parameters in #2116. |
impl<'w, T: Component> AsMut<T> for ResMut<'w, T> { | ||
fn as_mut(&mut self) -> &mut T { | ||
&mut *self | ||
} | ||
} | ||
|
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.
could you put this impl next to impl<'w, T: Component> AsRef<T> for ResMut<'w, T>
below?
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.
Good call, not sure how that got mixed up
It may be worth marking these |
I don't mind doing it, but I'm curious - is rustc not usually aggressive enough to make that necessary? |
Soo here's where I get a little confused, as yes I do believe the compiler is smart enough to inline this. However across the code base I've seen |
Because of the generics it would be possible for rustc to inline it even without Functions can only be inlined when they are codegened as part of the same crate. This only happens for functions from upstream crates when either |
@bjorn3 okay, done! |
Awesome looks good to me! |
bors r+ |
This can save users from having to type `&*X` all the time at the cost of some complexity in the type signature. For instance, this allows me to accommodate @jakobhellermann's suggestion in #1799 without requiring users to type `&*windows` 99% of the time.
Pull request successfully merged into main. Build succeeded: |
This can save users from having to type `&*X` all the time at the cost of some complexity in the type signature. For instance, this allows me to accommodate @jakobhellermann's suggestion in bevyengine#1799 without requiring users to type `&*windows` 99% of the time.
This can save users from having to type
&*X
all the time at the cost of some complexity in the type signature. For instance, this allows me to accommodate @jakobhellermann's suggestion in #1799 without requiring users to type&*windows
99% of the time.